diff --git a/common/djangoapps/static_replace/__init__.py b/common/djangoapps/static_replace/__init__.py index 088ba09181..fb1f48d143 100644 --- a/common/djangoapps/static_replace/__init__.py +++ b/common/djangoapps/static_replace/__init__.py @@ -16,18 +16,14 @@ def _url_replace_regex(prefix): """ Match static urls in quotes that don't end in '?raw'. - I'm sorry. http://xkcd.com/1171/ - - (?\\?['"]) # the opening quotes (?P{prefix}) # the prefix - (?P.*? # everything else in the url... - (?.*?) # everything else in the url (?P=quote) # the first matching closing quote """.format(prefix=prefix) @@ -84,6 +80,10 @@ def replace_static_urls(text, data_directory, course_namespace=None): quote = match.group('quote') rest = match.group('rest') + # Don't mess with things that end in '?raw' + if rest.endswith('?raw'): + return original + # course_namespace is not None, then use studio style urls if course_namespace is not None and not isinstance(modulestore(), XMLModuleStore): url = StaticContent.convert_legacy_static_url(rest, course_namespace) diff --git a/common/djangoapps/static_replace/test/test_static_replace.py b/common/djangoapps/static_replace/test/test_static_replace.py index 80b129f459..f23610e1bd 100644 --- a/common/djangoapps/static_replace/test/test_static_replace.py +++ b/common/djangoapps/static_replace/test/test_static_replace.py @@ -81,15 +81,22 @@ def test_data_dir_fallback(mock_storage, mock_modulestore, mock_settings): def test_raw_static_check(): + """ + Make sure replace_static_urls leaves alone things that end in '.raw' + """ path = '"/static/foo.png?raw"' assert_equals(path, replace_static_urls(path, DATA_DIRECTORY)) + text = 'text