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

Server-Side Rewrite: 'location' rewrite fix to avoid rewriting '$location' (#403)

* server-side rewrite: tweak 'location' rewrite to ensure $location is not rewritten!
tests: add additional rewrite tests for 'location', 'this.$location' and 'this.location'
This commit is contained in:
Ilya Kreymer 2018-10-31 20:18:18 -07:00 committed by GitHub
parent e1e8917bc3
commit f805f79388
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -93,7 +93,7 @@ if (!self.__WB_pmw) {{ self.__WB_pmw = function(obj) {{ return obj; }} }}\n\
rules = [
(r'(?<=\.)postMessage\b\(', self.add_prefix('__WB_pmw(self).'), 0),
(r'(?<!\.)\blocation\b\s*[=]\s*(?![=])', self.add_suffix(check_loc), 0),
(r'(?<![$.])\s*location\b\s*[=]\s*(?![=])', self.add_suffix(check_loc), 0),
(r'\breturn\s+this\b\s*(?![.$])', self.replace_str(this_rw), 0),
(r'(?<=[\n])\s*this\b(?=(?:\.(?:{0})\b))'.format(prop_str), self.replace_str(';' + this_rw), 0),
(r'(?<![$.])\s*this\b(?=(?:\.(?:{0})\b))'.format(prop_str), self.replace_str(this_rw), 0),

View File

@ -194,6 +194,22 @@ r"""
>>> _test_js_obj_proxy('return this.foo')
'return this.foo'
>>> _test_js_obj_proxy(r'this.$location = http://example.com/')
'this.$location = http://example.com/'
>>> _test_js_obj_proxy(r'this. $location = http://example.com/')
'this. $location = http://example.com/'
>>> _test_js_obj_proxy(r'this. _location = http://example.com/')
'this. _location = http://example.com/'
>>> _test_js_obj_proxy(r'this. alocation = http://example.com/')
'this. alocation = http://example.com/'
>>> _test_js_obj_proxy(r'this. location = http://example.com/')
'this. location = (self.__WB_check_loc && self.__WB_check_loc(location) || {}).href = http://example.com/'
#=================================================================
# XML Rewriting