Add leading period so we don't get partial matches on extensions.
This commit is contained in:
@@ -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 '<AssetExcludedExtensionsConfig(extensions={})>'.format(self.get_excluded_extensions().split())
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user