mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
server side rewriting: (#486)
- tweaked the JSWombatProxyRules regex for = this to be = this and , this - added comments to the more complicated regex's used by JSWombatProxyRules - added test case for tweaked regex
This commit is contained in:
parent
06513c2592
commit
db50efc558
@ -102,15 +102,23 @@ if (thisObj && thisObj._WB_wombat_obj_proxy) return thisObj._WB_wombat_obj_proxy
|
|||||||
prop_str = '|'.join(self.local_objs)
|
prop_str = '|'.join(self.local_objs)
|
||||||
|
|
||||||
rules = [
|
rules = [
|
||||||
|
# rewriting 'eval(....)' - invocation
|
||||||
(r'\beval\s*\(', self.add_prefix('WB_wombat_runEval(function _____evalIsEvil(_______eval_arg$$) { return eval(_______eval_arg$$); }.bind(this)).'), 0),
|
(r'\beval\s*\(', self.add_prefix('WB_wombat_runEval(function _____evalIsEvil(_______eval_arg$$) { return eval(_______eval_arg$$); }.bind(this)).'), 0),
|
||||||
|
# rewriting 'x = eval' - no invocation
|
||||||
(r'\beval\b', self.add_prefix('WB_wombat_'), 0),
|
(r'\beval\b', self.add_prefix('WB_wombat_'), 0),
|
||||||
(r'(?<=\.)postMessage\b\(', self.add_prefix('__WB_pmw(self).'), 0),
|
(r'(?<=\.)postMessage\b\(', self.add_prefix('__WB_pmw(self).'), 0),
|
||||||
(r'(?<![$.])\s*location\b\s*[=]\s*(?![=])', self.add_suffix(check_loc), 0),
|
(r'(?<![$.])\s*location\b\s*[=]\s*(?![=])', self.add_suffix(check_loc), 0),
|
||||||
|
# rewriting 'return this'
|
||||||
(r'\breturn\s+this\b\s*(?![.$])', self.replace_str(this_rw), 0),
|
(r'\breturn\s+this\b\s*(?![.$])', self.replace_str(this_rw), 0),
|
||||||
|
# rewriting 'this.' special properties access on new line, with ; prepended
|
||||||
(r'(?<=[\n])\s*this\b(?=(?:\.(?:{0})\b))'.format(prop_str), self.replace_str(';' + this_rw), 0),
|
(r'(?<=[\n])\s*this\b(?=(?:\.(?:{0})\b))'.format(prop_str), self.replace_str(';' + this_rw), 0),
|
||||||
|
# rewriting 'this.' special properties access, not on new line (no ;)
|
||||||
(r'(?<![$.])\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),
|
||||||
(r'(?<=[=])\s*this\b\s*(?![.$])', self.replace_str(this_rw), 0),
|
# rewrite '= this' or ', this'
|
||||||
|
(r'(?<=[=,])\s*this\b\s*(?![.$])', self.replace_str(this_rw), 0),
|
||||||
|
# rewrite ')(this)'
|
||||||
('\}(?:\s*\))?\s*\(this\)', self.replace_str(this_rw), 0),
|
('\}(?:\s*\))?\s*\(this\)', self.replace_str(this_rw), 0),
|
||||||
|
# rewrite this in && or || expr?
|
||||||
(r'(?<=[^|&][|&]{2})\s*this\b\s*(?)', self.replace_str(this_rw), 0),
|
(r'(?<=[^|&][|&]{2})\s*this\b\s*(?)', self.replace_str(this_rw), 0),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -175,6 +175,9 @@ r"""
|
|||||||
>>> _test_js_obj_proxy('a||this)')
|
>>> _test_js_obj_proxy('a||this)')
|
||||||
'a||_____WB$wombat$check$this$function_____(this))'
|
'a||_____WB$wombat$check$this$function_____(this))'
|
||||||
|
|
||||||
|
>>> _test_js_obj_proxy(r'(a,b,Q.contains(i[t], this))')
|
||||||
|
'(a,b,Q.contains(i[t], _____WB$wombat$check$this$function_____(this)))'
|
||||||
|
|
||||||
# not rewritten
|
# not rewritten
|
||||||
>>> _test_js_obj_proxy('var window = this$')
|
>>> _test_js_obj_proxy('var window = this$')
|
||||||
'var window = this$'
|
'var window = this$'
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user