diff options
| author | Tom Forbes <tom@tomforb.es> | 2019-07-21 21:55:25 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-07-23 10:03:23 +0200 |
| commit | 2ff517ccb6116c1be6338e6bdcf08a313defc5c7 (patch) | |
| tree | c766145aa24347403e7b42818791cfa20b0edb38 | |
| parent | 60dc957a825232fdda9138e2f8878b2ca407a7c9 (diff) | |
Fixed #30506 -- Fixed crash of autoreloader when path contains null characters.
| -rw-r--r-- | django/utils/autoreload.py | 4 | ||||
| -rw-r--r-- | docs/releases/2.2.4.txt | 3 | ||||
| -rw-r--r-- | tests/utils_tests/test_autoreload.py | 11 |
3 files changed, 18 insertions, 0 deletions
diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py index 25c3b44250..bf3b14609a 100644 --- a/django/utils/autoreload.py +++ b/django/utils/autoreload.py @@ -143,6 +143,10 @@ def iter_modules_and_files(modules, extra_files): # The module could have been removed, don't fail loudly if this # is the case. continue + except ValueError as e: + # Network filesystems may return null bytes in file paths. + logger.debug('"%s" raised when resolving path: "%s"' % (str(e), path)) + continue results.add(resolved_path) return frozenset(results) diff --git a/docs/releases/2.2.4.txt b/docs/releases/2.2.4.txt index 0ad92f4ab1..af0950d700 100644 --- a/docs/releases/2.2.4.txt +++ b/docs/releases/2.2.4.txt @@ -18,3 +18,6 @@ Bugfixes :class:`~django.contrib.postgres.fields.DateRangeField` or :class:`~django.contrib.postgres.fields.DateTimeRangeField`, if the right hand side of an expression is the same type (:ticket:`30621`). + +* Fixed a regression in Django 2.2 where auto-reloader crashes if a file path + contains nulls characters (``'\x00'``) (:ticket:`30506`). diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py index 1ea019ac7a..628749db01 100644 --- a/tests/utils_tests/test_autoreload.py +++ b/tests/utils_tests/test_autoreload.py @@ -140,6 +140,17 @@ class TestIterModulesAndFiles(SimpleTestCase): fake_main = types.ModuleType('__main__') self.assertEqual(autoreload.iter_modules_and_files((fake_main,), frozenset()), frozenset()) + def test_path_with_embedded_null_bytes(self): + for path in ( + 'embedded_null_byte\x00.py', + 'di\x00rectory/embedded_null_byte.py', + ): + with self.subTest(path=path): + self.assertEqual( + autoreload.iter_modules_and_files((), frozenset([path])), + frozenset(), + ) + class TestCommonRoots(SimpleTestCase): def test_common_roots(self): |
