Make replace_static_urls leave alone urls that have '?raw' at the end
- needed for GWT'ed modules that rely on the filename to find dependencies
This commit is contained in:
@@ -13,12 +13,22 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _url_replace_regex(prefix):
|
||||
"""
|
||||
Match static urls in quotes that don't end in '?raw'.
|
||||
|
||||
I'm sorry. http://xkcd.com/1171/
|
||||
|
||||
(?<!blah) means "don't match if the previous thing is blah". Clear, eh?
|
||||
(grep for negative lookbehind assertion in
|
||||
http://docs.python.org/2/library/re.html)
|
||||
"""
|
||||
return r"""
|
||||
(?x) # flags=re.VERBOSE
|
||||
(?P<quote>\\?['"]) # the opening quotes
|
||||
(?P<prefix>{prefix}) # theeprefix
|
||||
(?P<rest>.*?) # everything else in the url
|
||||
(?P=quote) # the first matching closing quote
|
||||
(?x) # flags=re.VERBOSE
|
||||
(?P<quote>\\?['"]) # the opening quotes
|
||||
(?P<prefix>{prefix}) # the prefix
|
||||
(?P<rest>.*? # everything else in the url...
|
||||
(?<!\?raw)) # ...but not if it has '?raw' at the end.
|
||||
(?P=quote) # the first matching closing quote
|
||||
""".format(prefix=prefix)
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
from nose.tools import assert_equals
|
||||
from static_replace import replace_static_urls, replace_course_urls
|
||||
import re
|
||||
|
||||
from nose.tools import assert_equals, assert_true, assert_false
|
||||
from static_replace import (replace_static_urls, replace_course_urls,
|
||||
_url_replace_regex)
|
||||
from mock import patch, Mock
|
||||
from xmodule.modulestore import Location
|
||||
from xmodule.modulestore.mongo import MongoModuleStore
|
||||
@@ -75,3 +78,27 @@ def test_data_dir_fallback(mock_storage, mock_modulestore, mock_settings):
|
||||
|
||||
mock_storage.exists.return_value = False
|
||||
assert_equals('"/static/data_dir/file.png"', replace_static_urls(STATIC_SOURCE, DATA_DIRECTORY))
|
||||
|
||||
|
||||
def test_raw_static_check():
|
||||
path = '"/static/foo.png?raw"'
|
||||
assert_equals(path, replace_static_urls(path, DATA_DIRECTORY))
|
||||
|
||||
|
||||
def test_regex():
|
||||
yes = ('"/static/foo.png"',
|
||||
'"/static/foo.png"',
|
||||
"'/static/foo.png'")
|
||||
no = ('"/static/foo.png?raw"',
|
||||
'"/static/foo', # no matching quote
|
||||
)
|
||||
|
||||
regex = _url_replace_regex('/static/')
|
||||
|
||||
for s in yes:
|
||||
print 'Should match: {0!r}'.format(s)
|
||||
assert_true(re.match(regex, s))
|
||||
|
||||
for s in no:
|
||||
print 'Should not match: {0!r}'.format(s)
|
||||
assert_false(re.match(regex, s))
|
||||
|
||||
Reference in New Issue
Block a user