mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 06:59:52 +01:00
regex rewrite: loosen rules for top & location rewrite, add tests
.WB_wombat_location and .WB_wombat_top overrides should help with less strict rewriting
This commit is contained in:
parent
0f0c20a03a
commit
a76dbefec2
@ -132,9 +132,7 @@ class JSLocationRewriterMixin(object):
|
|||||||
def __init__(self, rewriter, rules=[], prefix='WB_wombat_'):
|
def __init__(self, rewriter, rules=[], prefix='WB_wombat_'):
|
||||||
rules = rules + [
|
rules = rules + [
|
||||||
# (r'(?<![/$])\blocation\b(?!\":)', RegexRewriter.add_prefix(prefix), 0),
|
# (r'(?<![/$])\blocation\b(?!\":)', RegexRewriter.add_prefix(prefix), 0),
|
||||||
(r'(?<![/$\'"-])\b(?:location|top)\b(?!(?:\":|:|=\d|-))', RegexRewriter.add_prefix(prefix), 0),
|
(r'(?<![$\'"])\b(?:location|top)\b(?![$\'"])', RegexRewriter.add_prefix(prefix), 0),
|
||||||
|
|
||||||
(r'(?<=[?])location[:]', RegexRewriter.add_prefix(prefix), 0),
|
|
||||||
|
|
||||||
(r'(?<=\.)postMessage\b\(', RegexRewriter.add_prefix('__WB_pmw(window).'), 0),
|
(r'(?<=\.)postMessage\b\(', RegexRewriter.add_prefix('__WB_pmw(window).'), 0),
|
||||||
|
|
||||||
|
@ -55,6 +55,9 @@ r"""
|
|||||||
>>> _test_js('cool_Location = "http://example.com/abc.html"')
|
>>> _test_js('cool_Location = "http://example.com/abc.html"')
|
||||||
'cool_Location = "/web/20131010/http://example.com/abc.html"'
|
'cool_Location = "/web/20131010/http://example.com/abc.html"'
|
||||||
|
|
||||||
|
>>> _test_js('$location = cond ? a.location: location; location$')
|
||||||
|
'$location = cond ? a.WB_wombat_location: WB_wombat_location; location$'
|
||||||
|
|
||||||
# not rewriting WB_wombat_domain
|
# not rewriting WB_wombat_domain
|
||||||
#>>> _test_js('window.location = "http://example.com/abc.html" document.domain = "anotherdomain.com"')
|
#>>> _test_js('window.location = "http://example.com/abc.html" document.domain = "anotherdomain.com"')
|
||||||
#'window.WB_wombat_location = "/web/20131010/http://example.com/abc.html" document.WB_wombat_domain = "anotherdomain.com"'
|
#'window.WB_wombat_location = "/web/20131010/http://example.com/abc.html" document.WB_wombat_domain = "anotherdomain.com"'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user