mirror of
https://github.com/django/django.git
synced 2025-06-13 07:29:13 +00:00
[2.2.x] Fixed #30506 -- Fixed crash of autoreloader when path contains null characters.
Backport of 2ff517ccb6116c1be6338e6bdcf08a313defc5c7 from master.
This commit is contained in:
parent
506f800ead
commit
2d2859bec2
@ -135,11 +135,15 @@ def iter_modules_and_files(modules, extra_files):
|
|||||||
if not filename:
|
if not filename:
|
||||||
continue
|
continue
|
||||||
path = pathlib.Path(filename)
|
path = pathlib.Path(filename)
|
||||||
if not path.exists():
|
try:
|
||||||
# The module could have been removed, don't fail loudly if this
|
if not path.exists():
|
||||||
# is the case.
|
# The module could have been removed, don't fail loudly if this
|
||||||
continue
|
# is the case.
|
||||||
results.add(path.resolve().absolute())
|
continue
|
||||||
|
results.add(path.resolve().absolute())
|
||||||
|
except ValueError as e:
|
||||||
|
# Network filesystems may return null bytes in file paths.
|
||||||
|
logger.debug('"%s" raised when resolving path: "%s"' % (str(e), path))
|
||||||
return frozenset(results)
|
return frozenset(results)
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,3 +18,6 @@ Bugfixes
|
|||||||
:class:`~django.contrib.postgres.fields.DateRangeField` or
|
:class:`~django.contrib.postgres.fields.DateRangeField` or
|
||||||
:class:`~django.contrib.postgres.fields.DateTimeRangeField`, if the right
|
:class:`~django.contrib.postgres.fields.DateTimeRangeField`, if the right
|
||||||
hand side of an expression is the same type (:ticket:`30621`).
|
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`).
|
||||||
|
@ -138,6 +138,17 @@ class TestIterModulesAndFiles(SimpleTestCase):
|
|||||||
fake_main = types.ModuleType('__main__')
|
fake_main = types.ModuleType('__main__')
|
||||||
self.assertEqual(autoreload.iter_modules_and_files((fake_main,), frozenset()), frozenset())
|
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):
|
class TestCommonRoots(SimpleTestCase):
|
||||||
def test_common_roots(self):
|
def test_common_roots(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user