Restrict more characters (Closes #566)

This commit is contained in:
Philipp Hagemeister 2012-11-28 12:59:27 +01:00
parent 799c076384
commit 627dcfff39
2 changed files with 8 additions and 7 deletions

View File

@ -18,6 +18,7 @@ if sys.version_info < (3,0):
else:
_compat_str = lambda s: s
class TestUtil(unittest.TestCase):
def test_timeconvert(self):
self.assertTrue(timeconvert('') is None)
@ -66,7 +67,7 @@ class TestUtil(unittest.TestCase):
self.assertEqual(sanitize_filename(tests, restricted=True), 'a_b_c')
self.assertTrue(sanitize_filename(_compat_str('\xf6'), restricted=True) != '') # No empty filename
forbidden = '"\0\\/&!: \'\t\n'
forbidden = '"\0\\/&!: \'\t\n()[]{}$;`^,#'
for fc in forbidden:
for fbc in forbidden:
self.assertTrue(fbc not in sanitize_filename(fc, restricted=True))

View File

@ -330,7 +330,7 @@ def sanitize_filename(s, restricted=False):
return '_-' if restricted else ' -'
elif char in '\\/|*<>':
return '_'
if restricted and (char in '!&\'' or char.isspace()):
if restricted and (char in '!&\'()[]{}$;`^,#' or char.isspace()):
return '_'
if restricted and ord(char) > 127:
return '_'