Skip to content

Commit

Permalink
🐛 修复RegExp内容被覆盖的问题 #293 #289
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Jul 6, 2024
1 parent 389e6d2 commit 3ef9fbc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

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
Expand Up @@ -61,7 +61,7 @@
"@types/crypto-js": "^4.1.1",
"@types/eslint": "^8.4.10",
"@types/jest": "^28.1.6",
"@types/lodash": "^4.14.194",
"@types/lodash": "^4.17.6",
"@types/pako": "^2.0.0",
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
Expand Down
8 changes: 8 additions & 0 deletions src/pkg/utils/lodash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable import/prefer-default-export */

// 因为这个包出过好几次问题, 从原仓库单独剥离出来使用
// copyright: https://github.com/lodash/lodash

export function has(object: any, key: any) {
return object != null && Object.prototype.hasOwnProperty.call(object, key);
}
8 changes: 8 additions & 0 deletions src/runtime/content/exec_script.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,12 @@ describe("sandbox", () => {
const ret = await sandboxExec.exec();
expect(ret).toEqual(2);
});

// RegExp.$x 内容被覆盖 https://github.com/scriptscat/scriptcat/issues/293
it("RegExp", async () => {
scriptRes2.code = `let ok = /12(3)/.test('123');return RegExp.$1;`;
sandboxExec.scriptFunc = compileScript(compileScriptCode(scriptRes2));
const ret = await sandboxExec.exec();
expect(ret).toEqual("3");
});
});
2 changes: 1 addition & 1 deletion src/runtime/content/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MessageManager } from "@App/app/message/message";
import { ScriptRunResouce } from "@App/app/repo/scripts";
import { v4 as uuidv4 } from "uuid";
import has from "lodash/has";
import { has } from "@App/pkg/utils/lodash";
import GMApi, { ApiValue, GMContext } from "./gm_api";

// 构建脚本运行代码
Expand Down

0 comments on commit 3ef9fbc

Please sign in to comment.