1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

rewrite: fix js rewrite again to ensure '// comments' are not rewritten as scheme-rel urls

add tests
This commit is contained in:
Ilya Kreymer 2015-03-23 11:49:24 -07:00
parent bf0996c27a
commit 6acac67d3c
2 changed files with 8 additions and 1 deletions

View File

@ -113,7 +113,7 @@ class JSLinkRewriterMixin(object):
"""
#JS_HTTPX = r'(?:(?:(?<=["\';])https?:)|(?<=["\']))\\{0,4}/\\{0,4}/[A-Za-z0-9:_@.-]+.*(?=["\s\';&\\])'
#JS_HTTPX = r'(?<=["\';])(?:https?:)?\\{0,4}/\\{0,4}/[A-Za-z0-9:_@.\-/\\?&#]+(?=["\';&\\])'
JS_HTTPX = r'(?<=["\';])(?:https?:)?\\{0,4}/\\{0,4}/[A-Za-z0-9:_@.-]'
JS_HTTPX = r'(?<=["\';])(?:https?:)?\\{0,4}/\\{0,4}/[A-Za-z0-9:_@.-][^"\s\';&\\]*(?=["\';&\\])'
def __init__(self, rewriter, rules=[]):
rules = rules + [

View File

@ -32,6 +32,13 @@ r"""
>>> _test_js(r'location = "http://example.com/abc.html?^foo=http://abc.example.com"')
'WB_wombat_location = "/web/20131010/http://example.com/abc.html?^foo=http://abc.example.com"'
# don't rewrite comments, only scheme rel urls
>>> _test_js(r'location = "http://example.com/abc.html?^foo=http://abc.example.com";//some comments')
'WB_wombat_location = "/web/20131010/http://example.com/abc.html?^foo=http://abc.example.com";//some comments'
>>> _test_js(r'location = "//example.com/abc.html?^foo=http://abc.example.com"//some comments')
'WB_wombat_location = "/web/20131010/http://example.com/abc.html?^foo=http://abc.example.com"//some comments'
# not rewritten -- to be handled on client side
>>> _test_js(r'location = "/abc.html"')
'WB_wombat_location = "/abc.html"'