diff options
-rw-r--r-- | gemato/cli.py | 6 | ||||
-rw-r--r-- | gemato/exceptions.py | 15 | ||||
-rw-r--r-- | gemato/manifest.py | 5 | ||||
-rw-r--r-- | tests/test_manifest.py | 20 |
4 files changed, 46 insertions, 0 deletions
diff --git a/gemato/cli.py b/gemato/cli.py index 387303a..5027bfe 100644 --- a/gemato/cli.py +++ b/gemato/cli.py @@ -159,6 +159,9 @@ def do_update(args, argp): except gemato.exceptions.ManifestInvalidPath as e: logging.error(str(e)) return 1 + except gemato.exceptions.ManifestInvalidFilename as e: + logging.error(str(e)) + return 1 stop = timeit.default_timer() logging.info('{} updated in {:.2f} seconds'.format(p, stop - start)) @@ -223,6 +226,9 @@ def do_create(args, argp): except gemato.exceptions.ManifestInvalidPath as e: logging.error(str(e)) return 1 + except gemato.exceptions.ManifestInvalidFilename as e: + logging.error(str(e)) + return 1 stop = timeit.default_timer() logging.info('{} updated in {:.2f} seconds'.format(p, stop - start)) diff --git a/gemato/exceptions.py b/gemato/exceptions.py index b4fa29b..4127fb8 100644 --- a/gemato/exceptions.py +++ b/gemato/exceptions.py @@ -120,3 +120,18 @@ class ManifestInvalidPath(Exception): super(ManifestInvalidPath, self).__init__( "Attempting to add invalid path {} to Manifest: {} must not be {}" .format(path, detail[0], detail[1])) + + +class ManifestInvalidFilename(Exception): + """ + An exception raised when an entry for invalid filename is created. + """ + + __slots__ = ['filename', 'pos'] + + def __init__(self, filename, pos): + self.filename = filename + self.pos = pos + super(ManifestInvalidFilename, self).__init__( + "Attempting to add invalid filename {!r} to Manifest: disallowed character U+{:04X} at position {}" + .format(filename, ord(filename[pos]), pos)) diff --git a/gemato/manifest.py b/gemato/manifest.py index 7b482bc..b54674f 100644 --- a/gemato/manifest.py +++ b/gemato/manifest.py @@ -6,6 +6,7 @@ import datetime import io import os.path +import re import gemato.exceptions import gemato.openpgp @@ -54,9 +55,13 @@ class ManifestPathEntry(object): """ __slots__ = ['path'] + disallowed_path_re = re.compile(r'[\0\s]', re.U) def __init__(self, path): assert path[0] != '/' + m = self.disallowed_path_re.search(path) + if m is not None: + raise gemato.exceptions.ManifestInvalidFilename(path, m.start()) self.path = path @staticmethod diff --git a/tests/test_manifest.py b/tests/test_manifest.py index a99b31c..9995996 100644 --- a/tests/test_manifest.py +++ b/tests/test_manifest.py @@ -423,3 +423,23 @@ class NewManifestEntryTest(unittest.TestCase): gemato.manifest.new_manifest_entry('AUX', 'test', 32, {}), gemato.manifest.ManifestEntryAUX) + + def test_space_in_filename(self): + self.assertRaises(gemato.exceptions.ManifestInvalidFilename, + gemato.manifest.new_manifest_entry, 'DATA', + 'tes t', 32, {}), + + def test_tab_in_filename(self): + self.assertRaises(gemato.exceptions.ManifestInvalidFilename, + gemato.manifest.new_manifest_entry, 'DATA', + 'tes\tt', 32, {}), + + def test_nbsp_in_filename(self): + self.assertRaises(gemato.exceptions.ManifestInvalidFilename, + gemato.manifest.new_manifest_entry, 'DATA', + u'tes\u00a0t', 32, {}), + + def test_null_in_filename(self): + self.assertRaises(gemato.exceptions.ManifestInvalidFilename, + gemato.manifest.new_manifest_entry, 'DATA', + u'tes\0t', 32, {}), |