Skip to content

Commit 43d81ee

Browse files
committed
1 parent d5ba369 commit 43d81ee

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/zimscraperlib/rewriting/js.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ def create_js_rules() -> list[TransformationRule]:
153153

154154
return [
155155
# rewriting `eval(...)` - invocation
156-
(re.compile(r"(?:^|\s)\beval\s*\("), replace_prefix_from(eval_str, "eval")),
156+
(
157+
re.compile(r"(?<!static)(?<!function)(?<!})(?:^|\s)\beval\s*\("),
158+
replace_prefix_from(eval_str, "eval"),
159+
),
157160
(re.compile(r"\([\w]+,\s*eval\)\("), m2str(lambda _: f" {eval_str}")),
158161
# rewriting `x = eval` - no invocation
159162
(re.compile(r"[=]\s*\beval\b(?![(:.$])"), replace("eval", "self.eval")),

tests/rewriting/test_js_rewriting.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@ def test_import_rewrite(rewrite_import_content: ImportTestContent):
423423
",eval(a)",
424424
"this.$eval(a)",
425425
"x = $eval; x(a);",
426+
"static eval(a,b){ }",
427+
"function eval(a,b){ }",
428+
"} eval(a,b){ }",
426429
"obj = { eval : 1 }",
427430
"x = obj.eval",
428431
"x = obj.eval(a)",

0 commit comments

Comments
 (0)