Commit e57d1a20 by Toby Lawrence

Add leading period so we don't get partial matches on extensions.

parent 1183f6ce
...@@ -44,7 +44,8 @@ class AssetExcludedExtensionsConfig(ConfigurationModel): ...@@ -44,7 +44,8 @@ class AssetExcludedExtensionsConfig(ConfigurationModel):
@classmethod @classmethod
def get_excluded_extensions(cls): def get_excluded_extensions(cls):
"""Gets the excluded file extensions when canonicalizing static asset paths""" """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): def __repr__(self):
return '<AssetExcludedExtensionsConfig(extensions={})>'.format(self.get_excluded_extensions().split()) return '<AssetExcludedExtensionsConfig(extensions={})>'.format(self.get_excluded_extensions().split())
......
...@@ -445,6 +445,7 @@ class CanonicalContentTest(SharedModuleStoreTestCase): ...@@ -445,6 +445,7 @@ class CanonicalContentTest(SharedModuleStoreTestCase):
) )
@ddt.unpack @ddt.unpack
def test_canonical_asset_path_with_new_style_assets(self, base_url, start, expected, mongo_calls): def test_canonical_asset_path_with_new_style_assets(self, base_url, start, expected, mongo_calls):
exts = ['.html', '.tm']
prefix = 'split' prefix = 'split'
encoded_base_url = quote_plus('//' + base_url) encoded_base_url = quote_plus('//' + base_url)
c4x = 'c4x/a/b/asset' c4x = 'c4x/a/b/asset'
...@@ -473,7 +474,7 @@ class CanonicalContentTest(SharedModuleStoreTestCase): ...@@ -473,7 +474,7 @@ class CanonicalContentTest(SharedModuleStoreTestCase):
) )
with check_mongo_calls(mongo_calls): 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) self.assertEqual(asset_path, expected)
@ddt.data( @ddt.data(
...@@ -630,6 +631,7 @@ class CanonicalContentTest(SharedModuleStoreTestCase): ...@@ -630,6 +631,7 @@ class CanonicalContentTest(SharedModuleStoreTestCase):
) )
@ddt.unpack @ddt.unpack
def test_canonical_asset_path_with_c4x_style_assets(self, base_url, start, expected, mongo_calls): def test_canonical_asset_path_with_c4x_style_assets(self, base_url, start, expected, mongo_calls):
exts = ['.html', '.tm']
prefix = 'old' prefix = 'old'
c4x_block = 'c4x/a/b/asset' c4x_block = 'c4x/a/b/asset'
encoded_c4x_block = quote_plus('/' + c4x_block + '/') encoded_c4x_block = quote_plus('/' + c4x_block + '/')
...@@ -649,5 +651,5 @@ class CanonicalContentTest(SharedModuleStoreTestCase): ...@@ -649,5 +651,5 @@ class CanonicalContentTest(SharedModuleStoreTestCase):
) )
with check_mongo_calls(mongo_calls): 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) self.assertEqual(asset_path, expected)
...@@ -201,10 +201,8 @@ class StaticContent(object): ...@@ -201,10 +201,8 @@ class StaticContent(object):
# See if this is an allowed file extension to serve. Some files aren't served through the # 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. # CDN in order to avoid same-origin policy/CORS-related issues.
for excluded_ext in excluded_exts: if any(relative_path.lower().endswith(excluded_ext.lower()) for excluded_ext in excluded_exts):
if relative_path.lower().endswith(excluded_ext.lower()): serve_from_cdn = False
serve_from_cdn = False
break
# Update any query parameter values that have asset paths in them. This is for assets that # 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 # require their own after-the-fact values, like a Flash file that needs the path of a config
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment