From e46d0fcd57bdeb9e67f713a40c640e5ef0f09821 Mon Sep 17 00:00:00 2001 From: Matt Basta Date: Wed, 10 Jul 2013 16:57:32 -0700 Subject: [PATCH] Ban spaces around filenames (bug 891899) --- appvalidator/testcases/packagelayout.py | 13 +++++++++++++ tests/helper.py | 1 + tests/test_packagelayout.py | 18 +++++++++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/appvalidator/testcases/packagelayout.py b/appvalidator/testcases/packagelayout.py index f732918..a5b3517 100644 --- a/appvalidator/testcases/packagelayout.py +++ b/appvalidator/testcases/packagelayout.py @@ -29,6 +29,19 @@ def test_blacklisted_files(err, package=None): for name in package: file_ = package.info(name) + + if (file_["name_lower"].startswith(" ") or + file_["name_lower"].endswith(" ")): + err.error( + err_id=("packagelayout", "invalid_name"), + error="Filename starts with or ends with invalid character.", + description=["A filename within the package was found to " + "begin or end with a space. This is not " + "allowed.", + "Detected filename: '%s'" % name], + filename=name) + continue + # Simple test to ensure that the extension isn't blacklisted extension = file_["extension"] if extension in blacklisted_extensions: diff --git a/tests/helper.py b/tests/helper.py index 6c61c06..7da7dfa 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -169,6 +169,7 @@ class MockXPI: return True def info(self, name): + name = name.split('/')[-1] return {"name_lower": name.lower(), "extension": name.lower().split(".")[-1]} diff --git a/tests/test_packagelayout.py b/tests/test_packagelayout.py index 5f486c5..e8a415a 100644 --- a/tests/test_packagelayout.py +++ b/tests/test_packagelayout.py @@ -32,16 +32,28 @@ def test_duplicate_files(): """Test that duplicate files in a package are caught.""" package = MagicMock() - package.subpackage = False - zf = MagicMock() + package.zf = zf = MagicMock() zf.namelist.return_value = ["foo.bar", "foo.bar"] - package.zf = zf err = ErrorBundle() packagelayout.test_layout_all(err, package) assert err.failed() +def test_spaces_in_names(): + """Test that spaces in filenames are errors.""" + + package = MockXPI({ + "foo/bar/foo.bar ": None, + "foo/bar/ foo.bar": None, + }) + + err = ErrorBundle() + packagelayout.test_blacklisted_files(err, package) + assert err.failed() + assert len(err.errors) == 2 + + class TestMETAINF(TestCase): def setUp(self):