perf: Cross-domain settings - Regex validation rule error

This commit is contained in:
fit2cloud-chenyw
2025-09-02 19:41:49 +08:00
parent 9d458c3cd2
commit fa82f04357
2 changed files with 22 additions and 4 deletions
+20 -3
View File
@@ -199,7 +199,24 @@ const search = () => {
}
const termFormRef = ref()
const validateUrl = (_: any, value: any, callback: any) => {
if (value === '') {
callback(
new Error(
t('datasource.please_enter') + t('common.empty') + t('embedded.cross_domain_settings')
)
)
} else {
// var Expression = /(https?:\/\/)?([\da-z\.-]+)\.([a-z]{2,6})(:\d{1,5})?([\/\w\.-]*)*\/?(#[\S]+)?/ // eslint-disable-line
var Expression = /^https?:\/\/[^\s/?#]+(:\d+)?/i
var objExp = new RegExp(Expression)
if (objExp.test(value) && !value.endsWith('/')) {
callback()
} else {
callback(t('embedded.format_is_incorrect'))
}
}
}
const rules = {
name: [
{
@@ -210,8 +227,8 @@ const rules = {
domain: [
{
required: true,
message:
t('datasource.please_enter') + t('common.empty') + t('embedded.cross_domain_settings'),
validator: validateUrl,
trigger: 'blur',
},
],
}
@@ -258,7 +258,8 @@ const validateUrl = (_: any, value: any, callback: any) => {
)
)
} else {
var Expression = /(https?:\/\/)?([\da-z\.-]+)\.([a-z]{2,6})(:\d{1,5})?([\/\w\.-]*)*\/?(#[\S]+)?/ // eslint-disable-line
// var Expression = /(https?:\/\/)?([\da-z\.-]+)\.([a-z]{2,6})(:\d{1,5})?([\/\w\.-]*)*\/?(#[\S]+)?/ // eslint-disable-line
var Expression = /^https?:\/\/[^\s/?#]+(:\d+)?/i
var objExp = new RegExp(Expression)
if (objExp.test(value) && !value.endsWith('/')) {
callback()