对特殊变量里的特殊字符和换行符进行转义

This commit is contained in:
fofolee 2024-02-24 13:47:54 +08:00
parent a93bed8e3d
commit 867835b78e

View File

@ -1,62 +1,31 @@
<template> <template>
<div> <div>
<q-dialog <q-dialog v-model="isResultShow" :position="fromUtools ? 'top' : 'bottom'" @hide="stopRun" :maximized="fromUtools"
v-model="isResultShow" :transition-duration="fromUtools ? 0 : 200">
:position="fromUtools ? 'top' : 'bottom'" <q-card :style="{
@hide="stopRun" maxWidth: fromUtools ? '100%' : '700px',
:maximized="fromUtools" width: fromUtools ? '100%' : '700px',
:transition-duration="fromUtools ? 0 : 200" overflow: 'hidden',
> }">
<q-card <div v-if="!(enableHtml && fromUtools)" :style="{
:style="{ height: headerHeight + 'px',
maxWidth: fromUtools ? '100%' : '700px', }" class="flex items-center justify-between">
width: fromUtools ? '100%' : '700px',
overflow: 'hidden',
}"
>
<div
v-if="!(enableHtml && fromUtools)"
:style="{
height: headerHeight + 'px',
}"
class="flex items-center justify-between"
>
<div> <div>
<q-avatar :size="`${headerHeight}`"> <q-avatar :size="`${headerHeight}`">
<q-icon <q-icon :class="runResultStatus ? 'text-green' : 'text-red'"
:class="runResultStatus ? 'text-green' : 'text-red'" :name="runResultStatus ? 'task_alt' : 'error'"></q-icon>
:name="runResultStatus ? 'task_alt' : 'error'"
></q-icon>
</q-avatar> </q-avatar>
<span class="text-weight-bold text-h6">运行结果</span> <span class="text-weight-bold text-h6">运行结果</span>
</div> </div>
<ResultMenu <ResultMenu class="no-shadow" :stretch="true" :content="runResult.join('')" :closebtn="!fromUtools"
class="no-shadow" :textbtn="!enableHtml" :imagebtn="!enableHtml && isDataUrl" @showImg="showBase64Img" :style="{
:stretch="true"
:content="runResult.join('')"
:closebtn="!fromUtools"
:textbtn="!enableHtml"
:imagebtn="!enableHtml && isDataUrl"
@showImg="showBase64Img"
:style="{
height: headerHeight + 'px', height: headerHeight + 'px',
}" }" />
/>
</div> </div>
<div <div :style="{ maxHeight: maxHeight - headerHeight + 'px' }" class="scroll">
:style="{ maxHeight: maxHeight - headerHeight + 'px' }" <ResultArea v-if="isResultShow" @frameLoad="frameLoad" :frameInitHeight="frameInitHeight"
class="scroll" :enableHtml="enableHtml" :runResultStatus="runResultStatus" :runResult="runResult" :key="timeStamp"
> @mouseup="selectHandler" />
<ResultArea
v-if="isResultShow"
@frameLoad="frameLoad"
:frameInitHeight="frameInitHeight"
:enableHtml="enableHtml"
:runResultStatus="runResultStatus"
:runResult="runResult"
:key="timeStamp"
@mouseup="selectHandler"
/>
<q-resize-observer @resize="autoHeight" debounce="0" /> <q-resize-observer @resize="autoHeight" debounce="0" />
</div> </div>
<q-menu v-if="selectText" touch-position @before-hide="clearSelect"> <q-menu v-if="selectText" touch-position @before-hide="clearSelect">
@ -187,6 +156,15 @@ export default {
}; };
document.addEventListener("keydown", this.ctrlCListener); document.addEventListener("keydown", this.ctrlCListener);
}, },
//
escapeChars(string) {
return string
//
.replace(/`|'|"|\\/g, "\\$&")
//
.replace(/\r\n/g, "\\r\\n")
.replace(/\n/g, "\\n")
},
// //
assignSpecialVars(cmd) { assignSpecialVars(cmd) {
let userData = this.$root.utools.userData.all(); let userData = this.$root.utools.userData.all();
@ -195,7 +173,7 @@ export default {
let label = val.label.slice(0, -2); let label = val.label.slice(0, -2);
if (cmd.includes(label)) { if (cmd.includes(label)) {
let replData = label === "{{usr:" ? userData : this.$root.enterData; let replData = label === "{{usr:" ? userData : this.$root.enterData;
cmd = cmd.replace(val.match, (x) => val.repl(x, replData)); cmd = cmd.replace(val.match, (x) => this.escapeChars(val.repl(x, replData)));
} }
}); });
return cmd; return cmd;