Commit 71bebec5 by Toby Lawrence Committed by GitHub

Merge pull request #12986 from edx/PERF-351

Account for settings.STATIC_URL in XBlock resource URLs when rewriting them.
parents 0332ebea 8ab62b5b
......@@ -114,7 +114,11 @@ def process_static_urls(text, replacement_function, data_dir=None):
# Don't rewrite XBlock resource links. Probably wasn't a good idea that /static
# works for actual static assets and for magical course asset URLs....
full_url = prefix + rest
if full_url.startswith(XBLOCK_STATIC_RESOURCE_PREFIX):
starts_with_static_url = full_url.startswith(unicode(settings.STATIC_URL))
starts_with_prefix = full_url.startswith(XBLOCK_STATIC_RESOURCE_PREFIX)
contains_prefix = XBLOCK_STATIC_RESOURCE_PREFIX in full_url
if starts_with_prefix or (starts_with_static_url and contains_prefix):
return original
return replacement_function(original, prefix, quote, rest)
......
......@@ -4,6 +4,7 @@
import ddt
import re
from django.test import override_settings
from django.utils.http import urlquote, urlencode
from urlparse import urlparse, urlunparse, parse_qsl
from PIL import Image
......@@ -211,6 +212,22 @@ def test_static_url_with_xblock_resource(mock_modulestore, mock_storage):
assert_equals(post_text, replace_static_urls(pre_text, DATA_DIRECTORY, COURSE_KEY))
@patch('static_replace.staticfiles_storage', autospec=True)
@patch('static_replace.modulestore', autospec=True)
@override_settings(STATIC_URL='https://example.com/static/')
def test_static_url_with_xblock_resource_on_cdn(mock_modulestore, mock_storage):
"""
Make sure that for URLs with XBlock resource URL, which start with /static/,
we don't rewrite them, even if these are served from an absolute URL like a CDN.
"""
mock_storage.exists.return_value = False
mock_modulestore.return_value = Mock(MongoModuleStore)
pre_text = 'EMBED src ="https://example.com/static/xblock/resources/tehehe.xblock/public/images/woo.png"'
post_text = pre_text
assert_equals(post_text, replace_static_urls(pre_text, DATA_DIRECTORY, COURSE_KEY))
@ddt.ddt
class CanonicalContentTest(SharedModuleStoreTestCase):
"""
......
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