fix: prevent map management from passing required validation with space input (#6575)

This commit is contained in:
Katherine 2025-03-31 09:46:13 +08:00 committed by GitHub
parent c16d65ba7c
commit 19a263ff5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -32,15 +32,26 @@ const BaseConfiguration: React.FC<BaseConfigurationProps> = ({ type, children })
return apiClient.resource(MapConfigurationResourceKey);
}, [apiClient]);
function removeInvisibleCharsFromObject(obj: Record<string, string>): Record<string, string> {
const cleanObj: Record<string, string> = {};
function removeInvisibleCharsFromObject(obj: Record<string, string>): Record<string, string | null> {
const cleanObj: Record<string, string | null> = {};
for (const [key, value] of Object.entries(obj)) {
cleanObj[key] = typeof value === 'string' ? value.replace(/[\p{C}\p{Z}\p{Zl}\p{Zp}]+/gu, '') : value;
if (typeof value === 'string') {
// 去除不可见字符
const cleanedValue = value.replace(/[\p{C}\p{Z}\p{Zl}\p{Zp}]+/gu, '');
// 如果清理后为空字符串,则赋值为 null
cleanObj[key] = cleanedValue || null;
}
}
return cleanObj;
}
const onSubmit = async (values) => {
// 移除不可见字符并更新表单值
const result = removeInvisibleCharsFromObject(values);
form.setFieldsValue(result);
// 等待表单值更新完成后再校验
await new Promise((resolve) => setTimeout(resolve, 0));
await form.validateFields();
resource
.set({