使用JSON.stringify转义特殊变量

This commit is contained in:
fofolee 2024-02-25 12:55:25 +08:00
parent d65943fa84
commit ebb1b79b73

View File

@ -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) {