修复parseVarInput在处理特殊字符时的BUG

This commit is contained in:
fofolee 2025-01-08 16:40:18 +08:00
parent 8003497e71
commit ebbc7b7661
2 changed files with 8 additions and 8 deletions

View File

@ -293,16 +293,11 @@ export default defineComponent({
const value = this.getItemValue(option);
this.$emit("update:modelValue", newVarInputVal("str", value));
},
escapePath(paths) {
if (!paths) return null;
if (typeof paths === "string") return paths.replace(/\\/g, "\\\\");
return paths.map((path) => path.replace(/\\/g, "\\\\"));
},
handleFileOpen(dialog) {
let { type, options } = window.lodashM.cloneDeep(dialog);
if (!type) type = "open";
if (type === "open") {
const files = this.escapePath(utools.showOpenDialog(options));
const files = utools.showOpenDialog(options);
if (!files) return;
if (files.length > 1) {
this.$emit("update:modelValue", newVarInputVal("var", files));
@ -310,7 +305,7 @@ export default defineComponent({
this.$emit("update:modelValue", newVarInputVal("str", files[0]));
}
} else {
const file = this.escapePath(utools.showSaveDialog(options));
const file = utools.showSaveDialog(options);
if (!file) return;
this.$emit("update:modelValue", newVarInputVal("str", file));
}

View File

@ -37,5 +37,10 @@ export const newEmptyVarInputVal = (type = "str") => {
* @returns {string} 处理后的字符串
*/
export const stringifyVarInputVal = (argv) => {
return argv.isString ? `"${argv.value}"` : argv.value;
if (!argv.isString) return argv.value;
try {
return JSON.stringify(argv.value);
} catch (e) {
return `"${argv.value}"`;
}
};