feat: update variable validation regex for consistency in ExternalDataToolModal and schema

This commit is contained in:
twwu 2025-06-25 17:07:31 +08:00
parent 7d7fd18e65
commit c7cec120a6
2 changed files with 4 additions and 4 deletions

View File

@ -153,7 +153,7 @@ const ExternalDataToolModal: FC<ExternalDataToolModalProps> = ({
return
}
if (localeData.variable && !/[a-zA-Z_]\w{0,29}/g.test(localeData.variable)) {
if (localeData.variable && !/^[a-zA-Z_]\w{0,29}$/.test(localeData.variable)) {
notify({ type: 'error', message: t('appDebug.varKeyError.notValid', { key: t('appDebug.feature.tools.modal.variableName.title') }) })
return
}

View File

@ -25,14 +25,14 @@ export const createInputFieldSchema = (type: PipelineInputVarType, t: TFunction,
const { maxFileUploadLimit } = options
const commonSchema = z.object({
type: InputTypeEnum,
variable: z.string({
invalid_type_error: t('appDebug.varKeyError.notValid', { key: t('appDebug.variableConfig.varName') }),
}).nonempty({
variable: z.string().nonempty({
message: t('appDebug.varKeyError.canNoBeEmpty', { key: t('appDebug.variableConfig.varName') }),
}).max(MAX_VAR_KEY_LENGTH, {
message: t('appDebug.varKeyError.tooLong', { key: t('appDebug.variableConfig.varName') }),
}).regex(/^(?!\d)\w+/, {
message: t('appDebug.varKeyError.notStartWithNumber', { key: t('appDebug.variableConfig.varName') }),
}).regex(/^[a-zA-Z_]\w{0,29}$/, {
message: t('appDebug.varKeyError.notValid', { key: t('appDebug.variableConfig.varName') }),
}),
label: z.string().nonempty({
message: t('appDebug.variableConfig.errorMsg.labelNameRequired'),