Skip to content

Commit fa82f04

Browse files
perf: Cross-domain settings - Regex validation rule error
1 parent 9d458c3 commit fa82f04

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

frontend/src/views/system/embedded/Page.vue

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,24 @@ const search = () => {
199199
}
200200
201201
const termFormRef = ref()
202-
202+
const validateUrl = (_: any, value: any, callback: any) => {
203+
if (value === '') {
204+
callback(
205+
new Error(
206+
t('datasource.please_enter') + t('common.empty') + t('embedded.cross_domain_settings')
207+
)
208+
)
209+
} else {
210+
// var Expression = /(https?:\/\/)?([\da-z\.-]+)\.([a-z]{2,6})(:\d{1,5})?([\/\w\.-]*)*\/?(#[\S]+)?/ // eslint-disable-line
211+
var Expression = /^https?:\/\/[^\s/?#]+(:\d+)?/i
212+
var objExp = new RegExp(Expression)
213+
if (objExp.test(value) && !value.endsWith('/')) {
214+
callback()
215+
} else {
216+
callback(t('embedded.format_is_incorrect'))
217+
}
218+
}
219+
}
203220
const rules = {
204221
name: [
205222
{
@@ -210,8 +227,8 @@ const rules = {
210227
domain: [
211228
{
212229
required: true,
213-
message:
214-
t('datasource.please_enter') + t('common.empty') + t('embedded.cross_domain_settings'),
230+
validator: validateUrl,
231+
trigger: 'blur',
215232
},
216233
],
217234
}

frontend/src/views/system/embedded/iframe.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ const validateUrl = (_: any, value: any, callback: any) => {
258258
)
259259
)
260260
} else {
261-
var Expression = /(https?:\/\/)?([\da-z\.-]+)\.([a-z]{2,6})(:\d{1,5})?([\/\w\.-]*)*\/?(#[\S]+)?/ // eslint-disable-line
261+
// var Expression = /(https?:\/\/)?([\da-z\.-]+)\.([a-z]{2,6})(:\d{1,5})?([\/\w\.-]*)*\/?(#[\S]+)?/ // eslint-disable-line
262+
var Expression = /^https?:\/\/[^\s/?#]+(:\d+)?/i
262263
var objExp = new RegExp(Expression)
263264
if (objExp.test(value) && !value.endsWith('/')) {
264265
callback()

0 commit comments

Comments
 (0)