Browse Source
Merge in DEC/decision-webui-dcm from ~CRAWFORD.ZHOU/decision-webui-dcm:feature/x to feature/x * commit '9662daabda7970fca695dcad51759ccb984204e0': REPORT-91727 对用户输入的参数进行统一校验 feat:dcm仓库里面有两个场景,这里引入进来补充feature/x
Crawford.Zhou-周旭
2 years ago
5 changed files with 79 additions and 0 deletions
@ -0,0 +1,44 @@ |
|||||||
|
/* |
||||||
|
https://work.fineres.com/browse/REPORT-91724 用于参数统一校验
|
||||||
|
*/ |
||||||
|
import { ILLEGAL_STRINGS } from "./constant"; |
||||||
|
export type CheckResult = { |
||||||
|
legal: boolean, |
||||||
|
errorMsg: string, |
||||||
|
} |
||||||
|
export const CHECK_CORRECT: CheckResult = { |
||||||
|
legal: true, |
||||||
|
errorMsg: "", |
||||||
|
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* 检测非法字符,返回错误提示 |
||||||
|
* @param value 要校验的字符串 |
||||||
|
*/ |
||||||
|
export function checkIllegalStrings(value: string): CheckResult { |
||||||
|
// 后端传入的校验开关,如果没传,那也默认开启
|
||||||
|
const enabled = Dec.system.enableParameterVerify ?? true; |
||||||
|
if (enabled) { |
||||||
|
const illegalStringIndex = ILLEGAL_STRINGS.findIndex(s => value.includes(s)); |
||||||
|
if (illegalStringIndex === -1) { |
||||||
|
return CHECK_CORRECT; |
||||||
|
} |
||||||
|
|
||||||
|
return { |
||||||
|
legal: false, |
||||||
|
errorMsg: `${BI.i18nText("Dec-Basic_Check_Illegal_Strings")}${ILLEGAL_STRINGS[illegalStringIndex]}`, |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
return CHECK_CORRECT; |
||||||
|
} |
||||||
|
|
||||||
|
export function checkIllegalStringsInWidgetAndShowError(widget: any) { |
||||||
|
const value = widget.getValue(); |
||||||
|
const result = checkIllegalStrings(value); |
||||||
|
if (!result.legal) { |
||||||
|
widget.showError(result.errorMsg); |
||||||
|
} |
||||||
|
|
||||||
|
return result.legal; |
||||||
|
} |
@ -0,0 +1,15 @@ |
|||||||
|
/** |
||||||
|
* 参数检验的非法字符数组 |
||||||
|
*/ |
||||||
|
export const ILLEGAL_STRINGS = [ |
||||||
|
"\"", |
||||||
|
"<", |
||||||
|
">", |
||||||
|
"&", |
||||||
|
"/script", |
||||||
|
"javascript:", |
||||||
|
"onblur", |
||||||
|
"getRuntime", |
||||||
|
"ProcessBuilder", |
||||||
|
"java.lang.ProcessImpl", |
||||||
|
]; |
@ -0,0 +1 @@ |
|||||||
|
export { checkIllegalStringsInWidgetAndShowError, checkIllegalStrings } from "./checkIllegalStrings/checkIllegalStrings" |
Loading…
Reference in new issue