mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-30 13:02:46 +08:00
使用JSON.stringify转义特殊变量
This commit is contained in:
parent
d65943fa84
commit
ebb1b79b73
@ -156,14 +156,13 @@ export default {
|
|||||||
};
|
};
|
||||||
document.addEventListener("keydown", this.ctrlCListener);
|
document.addEventListener("keydown", this.ctrlCListener);
|
||||||
},
|
},
|
||||||
// 转义特殊变量里的特殊字符和换行符
|
|
||||||
escapeChars(string) {
|
escapeChars(string) {
|
||||||
return string
|
// 通过JSON.stringify,将特殊变量里所有特殊字符转义,输出为一个带双引号的字符串
|
||||||
// 转义特殊字符
|
return JSON.stringify(string)
|
||||||
.replace(/`|'|"|\\/g, "\\$&")
|
// 去掉两边双引号
|
||||||
// 转义换行字符
|
.slice(1, -1)
|
||||||
.replace(/\r\n/g, "\\r\\n")
|
// 单独转义单引号和反引号
|
||||||
.replace(/\n/g, "\\n")
|
.replace(/`|'/g, "\\$&")
|
||||||
},
|
},
|
||||||
// 特殊变量赋值
|
// 特殊变量赋值
|
||||||
assignSpecialVars(cmd) {
|
assignSpecialVars(cmd) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user