Skip to content

Commit

Permalink
rewriting: attempt to detect if inside string and skip 'this' rewriti…
Browse files Browse the repository at this point in the history
…ng, detects by checking for escaped quotes only so far

bump to 2.19.5
  • Loading branch information
ikreymer committed Aug 2, 2024
1 parent 519b47b commit 24013d0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
6 changes: 3 additions & 3 deletions dist/sw.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/wombat.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/wombatWorkers.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webrecorder/wabac",
"version": "2.19.4",
"version": "2.19.5",
"main": "index.js",
"type": "module",
"license": "AGPL-3.0-or-later",
Expand Down
21 changes: 20 additions & 1 deletion src/rewrite/jsrewriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ const createJSRules = () => {

const evalStr = "WB_wombat_runEval2((_______eval_arg, isGlobal) => { var ge = eval; return isGlobal ? ge(_______eval_arg) : eval(_______eval_arg); }).eval(this, (function() { return arguments })(),";

function isInString(string, offset) {
// partial detection when inside a string,
// check if nearest " are actually \"
// detects a subset of matches inside longer strings
let inx = string.lastIndexOf("\"", offset);
if (inx < 0) {
inx = string.indexOf("\"", offset);
}
if (inx > 0 && string[inx - 1] === "\\") {
// last " was a \", so likely inside string, don't rewrite
return true;
}
return false;
}
function addPrefix(prefix) {
return x => prefix + x;
}
Expand Down Expand Up @@ -63,7 +77,12 @@ const createJSRules = () => {
}

function replaceThis() {
return x => x.replace("this", thisRw);
return (x, _opts, offset, string) => {
if (isInString(string, offset)) {
return x;
}
return x.replace("this", thisRw);
};
}

function replace(src, target) {
Expand Down

0 comments on commit 24013d0

Please sign in to comment.