From e57d1a200606321d83bdb0673324f6647101dd38 Mon Sep 17 00:00:00 2001 From: Toby Lawrence Date: Tue, 2 Feb 2016 10:07:13 -0500 Subject: [PATCH] Add leading period so we don't get partial matches on extensions. --- common/djangoapps/static_replace/models.py | 3 ++- .../djangoapps/static_replace/test/test_static_replace.py | 6 ++++-- common/lib/xmodule/xmodule/contentstore/content.py | 6 ++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/common/djangoapps/static_replace/models.py b/common/djangoapps/static_replace/models.py index 8c73889c54..514adbbe77 100644 --- a/common/djangoapps/static_replace/models.py +++ b/common/djangoapps/static_replace/models.py @@ -44,7 +44,8 @@ class AssetExcludedExtensionsConfig(ConfigurationModel): @classmethod def get_excluded_extensions(cls): """Gets the excluded file extensions when canonicalizing static asset paths""" - return cls.current().excluded_extensions.split() + add_period = lambda x: '.' + x + return map(add_period, cls.current().excluded_extensions.split()) def __repr__(self): return ''.format(self.get_excluded_extensions().split()) diff --git a/common/djangoapps/static_replace/test/test_static_replace.py b/common/djangoapps/static_replace/test/test_static_replace.py index 37b2fc48db..bc203a85bc 100644 --- a/common/djangoapps/static_replace/test/test_static_replace.py +++ b/common/djangoapps/static_replace/test/test_static_replace.py @@ -445,6 +445,7 @@ class CanonicalContentTest(SharedModuleStoreTestCase): ) @ddt.unpack def test_canonical_asset_path_with_new_style_assets(self, base_url, start, expected, mongo_calls): + exts = ['.html', '.tm'] prefix = 'split' encoded_base_url = quote_plus('//' + base_url) c4x = 'c4x/a/b/asset' @@ -473,7 +474,7 @@ class CanonicalContentTest(SharedModuleStoreTestCase): ) with check_mongo_calls(mongo_calls): - asset_path = StaticContent.get_canonicalized_asset_path(self.courses[prefix].id, start, base_url, ['html']) + asset_path = StaticContent.get_canonicalized_asset_path(self.courses[prefix].id, start, base_url, exts) self.assertEqual(asset_path, expected) @ddt.data( @@ -630,6 +631,7 @@ class CanonicalContentTest(SharedModuleStoreTestCase): ) @ddt.unpack def test_canonical_asset_path_with_c4x_style_assets(self, base_url, start, expected, mongo_calls): + exts = ['.html', '.tm'] prefix = 'old' c4x_block = 'c4x/a/b/asset' encoded_c4x_block = quote_plus('/' + c4x_block + '/') @@ -649,5 +651,5 @@ class CanonicalContentTest(SharedModuleStoreTestCase): ) with check_mongo_calls(mongo_calls): - asset_path = StaticContent.get_canonicalized_asset_path(self.courses[prefix].id, start, base_url, ['html']) + asset_path = StaticContent.get_canonicalized_asset_path(self.courses[prefix].id, start, base_url, exts) self.assertEqual(asset_path, expected) diff --git a/common/lib/xmodule/xmodule/contentstore/content.py b/common/lib/xmodule/xmodule/contentstore/content.py index 89a269a5d0..b6f11e0979 100644 --- a/common/lib/xmodule/xmodule/contentstore/content.py +++ b/common/lib/xmodule/xmodule/contentstore/content.py @@ -201,10 +201,8 @@ class StaticContent(object): # See if this is an allowed file extension to serve. Some files aren't served through the # CDN in order to avoid same-origin policy/CORS-related issues. - for excluded_ext in excluded_exts: - if relative_path.lower().endswith(excluded_ext.lower()): - serve_from_cdn = False - break + if any(relative_path.lower().endswith(excluded_ext.lower()) for excluded_ext in excluded_exts): + serve_from_cdn = False # Update any query parameter values that have asset paths in them. This is for assets that # require their own after-the-fact values, like a Flash file that needs the path of a config