From 450067218d2fb3ebf64afe18dc20b9c8ff336b86 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 22 Jul 2015 17:51:54 -0700 Subject: framework: fix handling of files with a '.' in the name of the file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds a test and fixes it, so that when specifying a filename like 'foo.json..gz' it will work. Signed-off-by: Dylan Baker Tested-by: Michel Dänzer --- framework/backends/__init__.py | 4 +++- framework/tests/backends_tests.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/framework/backends/__init__.py b/framework/backends/__init__.py index 2950b3383..5ce4d6f30 100644 --- a/framework/backends/__init__.py +++ b/framework/backends/__init__.py @@ -135,7 +135,9 @@ def load(file_path): # i.e: Use .json.gz rather that .gz if extension in COMPRESSION_SUFFIXES: compression = extension[1:] # Drop the leading '.' - extension = os.path.splitext(name)[1] + # Remove any trailing '.', this fixes a bug where the filename + # is 'foo.json..xz, or similar + extension = os.path.splitext(name.rstrip('.'))[1] return extension, compression diff --git a/framework/tests/backends_tests.py b/framework/tests/backends_tests.py index 8084cdf00..f2fad1108 100644 --- a/framework/tests/backends_tests.py +++ b/framework/tests/backends_tests.py @@ -197,3 +197,18 @@ def test_set_meta_notimplemented(): """backends.load(): An error is raised if a set_meta isn't properly implmented. """ backends.set_meta('test_backend', {}) + + +@nt.with_setup(_notimplemented_setup, _registry_teardown) +@nt.raises(backends.BackendNotImplementedError) +@utils.not_raises(backends.BackendError) +def test_load_trailing_dot(): + """framework.backends.load: handles the result name ending in '.' + + Basically if this reaches a BackendNotImplementedError, then the '.' was + handled correctly, otherwise if it's '.' then we should reach the + BackendError, which is incorrect. + + """ + backends.load('foo.test_backend..gz') + -- cgit v1.2.3