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

server-side rewrite: more careful '|| this || that' rewriting to exclude regex '||this|that'

This commit is contained in:
Ilya Kreymer 2017-10-05 22:06:14 -07:00
parent 902f6659f4
commit 22ff4bd976
2 changed files with 13 additions and 1 deletions

View File

@ -196,7 +196,7 @@ if (!self.__WB_pmw) {{ self.__WB_pmw = function(obj) {{ return obj; }} }}\n\
(r'(?<=[\n])\s*this\b(?=(?:\.(?:{0})\b))'.format(prop_str), self.replace_str(';' + self.THIS_RW), 0),
(r'(?<![$.])\s*this\b(?=(?:\.(?:{0})\b))'.format(prop_str), self.replace_str(self.THIS_RW), 0),
(r'(?<=[=])\s*this\b\s*(?![.$])', self.replace_str(self.THIS_RW), 0),
(r'(?<=[^|&][|&]{2})\s*this\b\s*(?![.$])', self.replace_str(self.THIS_RW), 0),
(r'(?<=[^|&][|&]{2})\s*this\b\s*(?![|&.$]([^|&]|$))', self.replace_str(self.THIS_RW), 0),
]
super(JSWombatProxyRewriterMixin, self).__init__(rewriter, rules)

View File

@ -160,6 +160,12 @@ r"""
>>> _test_js_obj_proxy('var foo = that || this ;')
'var foo = that || (this && this._WB_wombat_obj_proxy || this) ;'
>>> _test_js_obj_proxy('a||this||that')
'a||(this && this._WB_wombat_obj_proxy || this)||that'
>>> _test_js_obj_proxy('a||this)')
'a||(this && this._WB_wombat_obj_proxy || this))'
# not rewritten
>>> _test_js_obj_proxy('var window = this$')
'var window = this$'
@ -170,6 +176,12 @@ r"""
>>> _test_js_obj_proxy('|||this|||')
'|||this|||'
>>> _test_js_obj_proxy('a||this|that')
'a||this|that'
>>> _test_js_obj_proxy('a||this$')
'a||this$'
>>> _test_js_obj_proxy('return this.foo')
'return this.foo'