Fix allow-unsafe-ext compat option (#16920)
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Core Tests / Core tests (ubuntu-latest, 3.11) (push) Has been cancelled
Core Tests / Core tests (ubuntu-latest, 3.12) (push) Has been cancelled
Core Tests / Core tests (ubuntu-latest, 3.13) (push) Has been cancelled
Core Tests / Core tests (ubuntu-latest, 3.14) (push) Has been cancelled
Core Tests / Core tests (ubuntu-latest, 3.15) (push) Has been cancelled
Core Tests / Core tests (ubuntu-latest, pypy-3.11) (push) Has been cancelled
Core Tests / Core tests (windows-latest, 3.10) (push) Has been cancelled
Core Tests / Core tests (windows-latest, 3.11) (push) Has been cancelled
Core Tests / Core tests (windows-latest, 3.12) (push) Has been cancelled
Core Tests / Core tests (windows-latest, 3.13) (push) Has been cancelled
Core Tests / Core tests (windows-latest, 3.14) (push) Has been cancelled
Core Tests / Core tests (windows-latest, 3.15) (push) Has been cancelled
Core Tests / Core tests (windows-latest, pypy-3.11) (push) Has been cancelled
Quick Test / Core test (push) Has been cancelled
Quick Test / Code check (push) Has been cancelled
Release (master) / Publish GitHub release (push) Has been cancelled
Release (master) / Publish to PyPI (push) Has been cancelled
Test and lint workflows / Check workflows (push) Has been cancelled
Test and lint workflows / Run zizmor (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Core Tests / Core tests (ubuntu-latest, 3.11) (push) Has been cancelled
Core Tests / Core tests (ubuntu-latest, 3.12) (push) Has been cancelled
Core Tests / Core tests (ubuntu-latest, 3.13) (push) Has been cancelled
Core Tests / Core tests (ubuntu-latest, 3.14) (push) Has been cancelled
Core Tests / Core tests (ubuntu-latest, 3.15) (push) Has been cancelled
Core Tests / Core tests (ubuntu-latest, pypy-3.11) (push) Has been cancelled
Core Tests / Core tests (windows-latest, 3.10) (push) Has been cancelled
Core Tests / Core tests (windows-latest, 3.11) (push) Has been cancelled
Core Tests / Core tests (windows-latest, 3.12) (push) Has been cancelled
Core Tests / Core tests (windows-latest, 3.13) (push) Has been cancelled
Core Tests / Core tests (windows-latest, 3.14) (push) Has been cancelled
Core Tests / Core tests (windows-latest, 3.15) (push) Has been cancelled
Core Tests / Core tests (windows-latest, pypy-3.11) (push) Has been cancelled
Quick Test / Core test (push) Has been cancelled
Quick Test / Code check (push) Has been cancelled
Release (master) / Publish GitHub release (push) Has been cancelled
Release (master) / Publish to PyPI (push) Has been cancelled
Test and lint workflows / Check workflows (push) Has been cancelled
Test and lint workflows / Run zizmor (push) Has been cancelled
Fix bug in e578e265f7
Closes #16919
Authored by: bashonly
This commit is contained in:
@@ -327,6 +327,12 @@ class TestUtil(unittest.TestCase):
|
||||
with self.assertRaises(_UnsafeExtensionError):
|
||||
prepend_extension('abc.unexpected_ext', ext, 'ext')
|
||||
|
||||
# Test allow-unsafe-ext compat option
|
||||
_UnsafeExtensionError._enabled = False
|
||||
self.assertEqual(prepend_extension('abc.ext', 'un/safe'), 'abc.un/safe.ext')
|
||||
# Re-enable sanitization for other tests
|
||||
_UnsafeExtensionError._enabled = True
|
||||
|
||||
def test_replace_extension(self):
|
||||
self.assertEqual(replace_extension('abc.ext', 'temp'), 'abc.temp')
|
||||
self.assertEqual(replace_extension('abc.ext', 'temp', 'ext'), 'abc.temp')
|
||||
@@ -345,6 +351,12 @@ class TestUtil(unittest.TestCase):
|
||||
with self.assertRaises(_UnsafeExtensionError):
|
||||
replace_extension('abc.unexpected_ext', ext, 'ext')
|
||||
|
||||
# Test allow-unsafe-ext compat option
|
||||
_UnsafeExtensionError._enabled = False
|
||||
self.assertEqual(replace_extension('abc.ext', 'bin'), 'abc.bin')
|
||||
# Re-enable sanitization for other tests
|
||||
_UnsafeExtensionError._enabled = True
|
||||
|
||||
def test_subtitles_filename(self):
|
||||
self.assertEqual(subtitles_filename('abc.ext', 'en', 'vtt'), 'abc.en.vtt')
|
||||
self.assertEqual(subtitles_filename('abc.ext', 'en', 'vtt', 'ext'), 'abc.en.vtt')
|
||||
|
||||
+1
-1
@@ -619,7 +619,7 @@ def validate_options(opts):
|
||||
warnings.append(
|
||||
'Using allow-unsafe-ext opens you up to potential attacks. '
|
||||
'Use with great care!')
|
||||
_UnsafeExtensionError.sanitize_extension = lambda x, prepend=False: x
|
||||
_UnsafeExtensionError._enabled = False
|
||||
|
||||
return warnings, deprecation_warnings
|
||||
|
||||
|
||||
@@ -5218,12 +5218,17 @@ class _UnsafeExtensionError(Exception):
|
||||
'sbv',
|
||||
])
|
||||
|
||||
_enabled = True
|
||||
|
||||
def __init__(self, extension, /):
|
||||
super().__init__(f'unsafe file extension: {extension!r}')
|
||||
self.extension = extension
|
||||
|
||||
@classmethod
|
||||
def sanitize_extension(cls, extension, /, *, prepend=False, _allowed_exts=()):
|
||||
if not cls._enabled:
|
||||
return extension
|
||||
|
||||
if extension is None:
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user