Skip to content

Commit 498ce0d

Browse files
authored
🐛 修改 dealScript 处理,不需使用RegExp,让浏览器自行判断特殊字符转换 (#997)
1 parent e4e5386 commit 498ce0d

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

src/pkg/utils/utils.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@ export function randomString(e: number) {
1717
return n;
1818
}
1919

20-
export function dealSymbol(source: string): string {
21-
source = source.replace(/("|\\)/g, "\\$1");
22-
source = source.replace(/(\r\n|\n)/g, "\\n");
23-
return source;
24-
}
25-
2620
export function dealScript(source: string): string {
27-
return dealSymbol(source);
21+
// 双引号会加quote. 其他特殊字符也会转换一下。然后整个文字加双引号表示字串
22+
// 例子 `This is a "Apple".\n123\n\r456` => `"This is a \\"Apple\\".\\n123\\n\\r456"`
23+
// 兼容旧代码,头尾引号删去。
24+
return JSON.stringify(source).slice(1, -1);
2825
}
2926

3027
export function isFirefox(): boolean {

0 commit comments

Comments
 (0)