Skip to content

Commit 3ef9fbc

Browse files
committed
🐛 修复RegExp内容被覆盖的问题 #293 #289
1 parent 389e6d2 commit 3ef9fbc

5 files changed

Lines changed: 27 additions & 11 deletions

File tree

‎package-lock.json‎

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"@types/crypto-js": "^4.1.1",
6262
"@types/eslint": "^8.4.10",
6363
"@types/jest": "^28.1.6",
64-
"@types/lodash": "^4.14.194",
64+
"@types/lodash": "^4.17.6",
6565
"@types/pako": "^2.0.0",
6666
"@types/react": "^18.0.15",
6767
"@types/react-dom": "^18.0.6",

‎src/pkg/utils/lodash.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* eslint-disable import/prefer-default-export */
2+
3+
// 因为这个包出过好几次问题, 从原仓库单独剥离出来使用
4+
// copyright: https://github.com/lodash/lodash
5+
6+
export function has(object: any, key: any) {
7+
return object != null && Object.prototype.hasOwnProperty.call(object, key);
8+
}

‎src/runtime/content/exec_script.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,12 @@ describe("sandbox", () => {
109109
const ret = await sandboxExec.exec();
110110
expect(ret).toEqual(2);
111111
});
112+
113+
// RegExp.$x 内容被覆盖 https://github.com/scriptscat/scriptcat/issues/293
114+
it("RegExp", async () => {
115+
scriptRes2.code = `let ok = /12(3)/.test('123');return RegExp.$1;`;
116+
sandboxExec.scriptFunc = compileScript(compileScriptCode(scriptRes2));
117+
const ret = await sandboxExec.exec();
118+
expect(ret).toEqual("3");
119+
});
112120
});

‎src/runtime/content/utils.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { MessageManager } from "@App/app/message/message";
22
import { ScriptRunResouce } from "@App/app/repo/scripts";
33
import { v4 as uuidv4 } from "uuid";
4-
import has from "lodash/has";
4+
import { has } from "@App/pkg/utils/lodash";
55
import GMApi, { ApiValue, GMContext } from "./gm_api";
66

77
// 构建脚本运行代码

0 commit comments

Comments
 (0)