@@ -101,6 +101,40 @@ def test_js_rewrite_post_message(simple_js_rewriter: JsRewriter):
101
101
)
102
102
103
103
104
+ @pytest .mark .parametrize (
105
+ "raw_js,expected" ,
106
+ [
107
+ pytest .param ("x = eval; x(a);" , "x = self.eval; x(a);" , id = "case1" ),
108
+ pytest .param (
109
+ " eval(a)" ,
110
+ " WB_wombat_runEval2((_______eval_arg, isGlobal) => { var ge = eval; "
111
+ "return isGlobal ? ge(_______eval_arg) : eval(_______eval_arg); })"
112
+ ".eval(this, (function() { return arguments })(),a)" ,
113
+ id = "case2" ,
114
+ ),
115
+ pytest .param (
116
+ "$eval = eval; $eval(a);" , "$eval = self.eval; $eval(a);" , id = "case3"
117
+ ),
118
+ pytest .param (
119
+ "foo(a, eval(data));" ,
120
+ "foo(a, WB_wombat_runEval2((_______eval_arg, isGlobal) => { var ge = eval; "
121
+ "return isGlobal ? ge(_______eval_arg) : eval(_______eval_arg); })"
122
+ ".eval(this, (function() { return arguments })(),data));" ,
123
+ id = "case4" ,
124
+ ),
125
+ pytest .param (
126
+ "return(1, eval)(data);" ,
127
+ "return WB_wombat_runEval2((_______eval_arg, isGlobal) => { var ge = eval; "
128
+ "return isGlobal ? ge(_______eval_arg) : eval(_______eval_arg); })"
129
+ ".eval(this, (function() { return arguments })(),data);" ,
130
+ id = "case5" ,
131
+ ),
132
+ ],
133
+ )
134
+ def test_js_rewrite_evals (simple_js_rewriter : JsRewriter , raw_js : str , expected : str ):
135
+ assert simple_js_rewriter .rewrite (raw_js ) == expected
136
+
137
+
104
138
class WrappedTestContent (ContentForTests ):
105
139
106
140
def __init__ (
@@ -173,11 +207,20 @@ def wrap_script(text: str) -> str:
173
207
input_ = "this. location = 'http://example.com/'" ,
174
208
expected = "this. location = 'http://example.com/'" ,
175
209
),
210
+ WrappedTestContent (
211
+ input_ = "abc-location = http://example.com/" ,
212
+ expected = "abc-location = http://example.com/" ,
213
+ ),
214
+ WrappedTestContent (
215
+ input_ = "func(location = 0)" ,
216
+ expected = "func(location = 0)" ,
217
+ ),
176
218
WrappedTestContent (
177
219
input_ = "if (self.foo) { console.log('blah') }" ,
178
220
expected = "if (self.foo) { console.log('blah') }" ,
179
221
),
180
222
WrappedTestContent (input_ = "window.x = 5" , expected = "window.x = 5" ),
223
+ WrappedTestContent (input_ = " var self " , expected = " let self " ),
181
224
]
182
225
)
183
226
def rewrite_wrapped_content (request : pytest .FixtureRequest ):
0 commit comments