mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
js regex rewrite: fix tertiary op rewrite, remove commented out regexs, add a few more tests
This commit is contained in:
parent
15ad56c024
commit
69af57dedf
@ -142,26 +142,13 @@ class JSLocationRewriterMixin(object):
|
||||
|
||||
def __init__(self, rewriter, rules=[], prefix='WB_wombat_'):
|
||||
rules = rules + [
|
||||
# (r'(?<![/$])\blocation\b(?!\":)', RegexRewriter.add_prefix(prefix), 0),
|
||||
(r'(?<![$\'"])\b(?:location|top)\b(?![$\'":])', RegexRewriter.add_prefix(prefix), 0),
|
||||
|
||||
(r'(?<=\.)postMessage\b\(', RegexRewriter.add_prefix('__WB_pmw(window).'), 0),
|
||||
(r'(?<=[?])\s*(?:\w+[.])?(location)\s*(?=[:])', RegexRewriter.add_prefix(prefix), 1),
|
||||
|
||||
(r'(?<=\.)postMessage\b\(', RegexRewriter.add_prefix('__WB_pmw(self.window).'), 0),
|
||||
|
||||
(r'(?<=\.)frameElement\b', RegexRewriter.add_prefix(prefix), 0),
|
||||
# (r'(?<=document\.)domain', RegexRewriter.add_prefix(prefix), 0),
|
||||
# (r'(?<=document\.)referrer', RegexRewriter.add_prefix(prefix), 0),
|
||||
# (r'(?<=document\.)cookie', RegexRewriter.add_prefix(prefix), 0),
|
||||
|
||||
#todo: move to mixin?
|
||||
#(r'(?<=[\s=(){])(top)\s*(?:[!}?)]|==|$)',
|
||||
# (r'(?<=[\s=(){.])(top)\s*(?:[,!}?)]|==|$)',
|
||||
# RegexRewriter.add_prefix(prefix), 1),
|
||||
|
||||
# (r'^(top)\s*(?:[!})]|==|$)',
|
||||
# RegexRewriter.add_prefix(prefix), 1),
|
||||
|
||||
# (r'(?<=window\.)(top)',
|
||||
# RegexRewriter.add_prefix(prefix), 1),
|
||||
]
|
||||
super(JSLocationRewriterMixin, self).__init__(rewriter, rules)
|
||||
|
||||
|
@ -58,6 +58,14 @@ r"""
|
||||
>>> _test_js('$location = cond ? a.location: location; location$')
|
||||
'$location = cond ? a.WB_wombat_location: WB_wombat_location; location$'
|
||||
|
||||
>>> _test_js('location$ = cond?a.location:location;')
|
||||
'location$ = cond?a.WB_wombat_location:WB_wombat_location;'
|
||||
|
||||
>>> _test_js('location$ = {location: "location", top: " location "}')
|
||||
'location$ = {location: "location", top: " WB_wombat_location "}'
|
||||
|
||||
|
||||
|
||||
# not rewriting WB_wombat_domain
|
||||
#>>> _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"'
|
||||
|
Loading…
x
Reference in New Issue
Block a user