mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 14:34:13 +08:00
优化转义规则
This commit is contained in:
parent
fbae2864b2
commit
10d7ab200e
@ -3,13 +3,13 @@
|
|||||||
<q-dialog v-model="isResultShow" :position="fromUtools ? 'top' : 'bottom'" @hide="stopRun" :maximized="fromUtools"
|
<q-dialog v-model="isResultShow" :position="fromUtools ? 'top' : 'bottom'" @hide="stopRun" :maximized="fromUtools"
|
||||||
:transition-duration="fromUtools ? 0 : 200">
|
:transition-duration="fromUtools ? 0 : 200">
|
||||||
<q-card :style="{
|
<q-card :style="{
|
||||||
maxWidth: fromUtools ? '100%' : '700px',
|
maxWidth: fromUtools ? '100%' : '700px',
|
||||||
width: fromUtools ? '100%' : '700px',
|
width: fromUtools ? '100%' : '700px',
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
}">
|
}">
|
||||||
<div v-if="!(enableHtml && fromUtools)" :style="{
|
<div v-if="!(enableHtml && fromUtools)" :style="{
|
||||||
height: headerHeight + 'px',
|
height: headerHeight + 'px',
|
||||||
}" class="flex items-center justify-between">
|
}" class="flex items-center justify-between">
|
||||||
<div>
|
<div>
|
||||||
<q-avatar :size="`${headerHeight}`">
|
<q-avatar :size="`${headerHeight}`">
|
||||||
<q-icon :class="runResultStatus ? 'text-green' : 'text-red'"
|
<q-icon :class="runResultStatus ? 'text-green' : 'text-red'"
|
||||||
@ -19,8 +19,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<ResultMenu class="no-shadow" :stretch="true" :content="runResult.join('')" :closebtn="!fromUtools"
|
<ResultMenu class="no-shadow" :stretch="true" :content="runResult.join('')" :closebtn="!fromUtools"
|
||||||
:textbtn="!enableHtml" :imagebtn="!enableHtml && isDataUrl" @showImg="showBase64Img" :style="{
|
:textbtn="!enableHtml" :imagebtn="!enableHtml && isDataUrl" @showImg="showBase64Img" :style="{
|
||||||
height: headerHeight + 'px',
|
height: headerHeight + 'px',
|
||||||
}" />
|
}" />
|
||||||
</div>
|
</div>
|
||||||
<div :style="{ maxHeight: maxHeight - headerHeight + 'px' }" class="scroll">
|
<div :style="{ maxHeight: maxHeight - headerHeight + 'px' }" class="scroll">
|
||||||
<ResultArea v-if="isResultShow" @frameLoad="frameLoad" :frameInitHeight="frameInitHeight"
|
<ResultArea v-if="isResultShow" @frameLoad="frameLoad" :frameInitHeight="frameInitHeight"
|
||||||
@ -156,13 +156,27 @@ export default {
|
|||||||
};
|
};
|
||||||
document.addEventListener("keydown", this.ctrlCListener);
|
document.addEventListener("keydown", this.ctrlCListener);
|
||||||
},
|
},
|
||||||
escapeChars(string) {
|
escapeItem(item) {
|
||||||
// 通过JSON.stringify,将特殊变量里所有特殊字符转义,输出为一个带双引号的字符串
|
// 无论什么类型,先转为String
|
||||||
return JSON.stringify(string)
|
if (typeof item === 'object') {
|
||||||
|
try {
|
||||||
|
item = JSON.stringify(item)
|
||||||
|
} catch (_) {
|
||||||
|
item = item.toString()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
item = item.toString()
|
||||||
|
}
|
||||||
|
// 通过JSON.stringify,将所有特殊字符转义,输出为一个带双引号的字符串
|
||||||
|
item = JSON.stringify(item)
|
||||||
// 去掉两边双引号
|
// 去掉两边双引号
|
||||||
.slice(1, -1)
|
.slice(1, -1)
|
||||||
// 单独转义单引号和反引号
|
// 单独转义单引号、反引号
|
||||||
.replace(/`|'/g, "\\$&")
|
.replace(/`|'/g, "\\$&")
|
||||||
|
// 转义双括号
|
||||||
|
.replace(/\{\{/g, "\\{\\{")
|
||||||
|
// .replace("$", '$$$')
|
||||||
|
return item
|
||||||
},
|
},
|
||||||
// 特殊变量赋值
|
// 特殊变量赋值
|
||||||
assignSpecialVars(cmd) {
|
assignSpecialVars(cmd) {
|
||||||
@ -172,7 +186,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) => this.escapeChars(val.repl(x, replData)));
|
cmd = cmd.replace(val.match, (x) => this.escapeItem(val.repl(x, replData)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return cmd;
|
return cmd;
|
||||||
|
@ -2,17 +2,11 @@
|
|||||||
* 所有的特殊变量
|
* 所有的特殊变量
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let escapeItem = item => {
|
|
||||||
if (typeof item === 'number') return item
|
|
||||||
item = typeof item === 'object' ? JSON.stringify(item) : item.replace(/\\/g, '\\\\')
|
|
||||||
return item.replace('$', '$$$')
|
|
||||||
}
|
|
||||||
|
|
||||||
let handlingJsonVar = (jsonVar, name, payload) => {
|
let handlingJsonVar = (jsonVar, name, payload) => {
|
||||||
try {
|
try {
|
||||||
return escapeItem(window.evalCodeInSandbox(jsonVar.slice(2, -2), {
|
return window.evalCodeInSandbox(jsonVar.slice(2, -2), {
|
||||||
[name]: payload
|
[name]: payload
|
||||||
}))
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return utools.showNotification(e)
|
return utools.showNotification(e)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user