1
0
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

 wombat
  - removed createTouch override as it is now deprecated and removed from major browsers
  - removed createTouch override check from the tests
This commit is contained in:
John Berlin 2019-06-29 02:04:02 -04:00 committed by Ilya Kreymer
parent d869f7ef48
commit 64196c8abc
5 changed files with 14 additions and 5 deletions

View File

@ -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),
] ]

View File

@ -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

View File

@ -5800,7 +5800,6 @@ Wombat.prototype.wombatInit = function() {
this.overrideFuncArgProxyToObj(this.$wbwindow.Node, 'contains'); this.overrideFuncArgProxyToObj(this.$wbwindow.Node, 'contains');
this.overrideFuncArgProxyToObj(this.$wbwindow.Document, 'createTreeWalker'); this.overrideFuncArgProxyToObj(this.$wbwindow.Document, 'createTreeWalker');
this.overrideFuncArgProxyToObj(this.$wbwindow.Document, 'evaluate', 1); this.overrideFuncArgProxyToObj(this.$wbwindow.Document, 'evaluate', 1);
this.overrideFuncArgProxyToObj(this.$wbwindow.Document, 'createTouch', 1);
this.overrideFuncArgProxyToObj( this.overrideFuncArgProxyToObj(
this.$wbwindow.XSLTProcessor, this.$wbwindow.XSLTProcessor,
'transformToFragment', 'transformToFragment',

View File

@ -580,8 +580,7 @@ exports.TestFunctionChanges = [
'open', 'open',
'createElementNS', 'createElementNS',
'evaluate', 'evaluate',
'createTreeWalker', 'createTreeWalker'
'createTouch'
] ]
}, },
{ {