From 2ab1b0bf1ba52622af3500b7488a2209adfedddb Mon Sep 17 00:00:00 2001 From: Sense T Date: Thu, 11 Apr 2024 12:10:57 +0800 Subject: [PATCH] rr validation --- .../components/records/RecordEditModal.vue | 43 +++++++++++++++++++ web/src/locale/en-US.ts | 8 +++- web/src/locale/zh-CN.ts | 8 +++- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/web/src/components/records/RecordEditModal.vue b/web/src/components/records/RecordEditModal.vue index a0ec36d..1f84b71 100644 --- a/web/src/components/records/RecordEditModal.vue +++ b/web/src/components/records/RecordEditModal.vue @@ -186,6 +186,30 @@ const rules = { return new Error(t('common.mandatory')) } + if (props.record.name.includes(' ')) { + invalidData.value &= ~validationFlags.name + return new Error(t('records.errors.hasSpace')) + } + + if (props.record.name.startsWith('.') || props.record.name.endsWith('.')) { + invalidData.value &= ~validationFlags.name + return new Error(t('records.errors.badName.dotAndMinus')) + } + + if (props.record.name.startsWith('-') || props.record.name.endsWith('-')) { + invalidData.value &= ~validationFlags.name + return new Error(t('records.errors.badName.dotAndMinus')) + } + + if (props.record.name.includes('..')) { + invalidData.value &= ~validationFlags.name + return new Error(t('records.errors.badName.doubleDots')) + } + + if (props.record.name.split('.').filter(e => e.length > 63).length > 0) { + invalidData.value &= ~validationFlags.name + return new Error(t('records.errors.badName.longerThan63')) + } return true } }, @@ -216,6 +240,10 @@ const rules = { return new Error(t('common.mandatory')) } + if (r.host.includes(' ')) { + invalidData.value &= ~validationFlags.content + return new Error(t('records.errors.hasSpace')) + } if (!r.host.endsWith('.')) { invalidData.value &= ~validationFlags.content @@ -268,6 +296,11 @@ const rules = { return new Error(t('common.mandatory')) } + if (r.host.includes(' ')) { + invalidData.value &= ~validationFlags.content + return new Error(t('records.errors.hasSpace')) + } + if (!r.host.endsWith('.')) { invalidData.value &= ~validationFlags.content return new Error(t('records.errors.endWithDot')) @@ -288,6 +321,11 @@ const rules = { return new Error(t('common.mandatory')) } + if (r.target.includes(' ')) { + invalidData.value &= ~validationFlags.content + return new Error(t('records.errors.hasSpace')) + } + if (!r.target.endsWith('.')) { invalidData.value &= ~validationFlags.content return new Error(t('records.errors.endWithDot')) @@ -308,6 +346,11 @@ const rules = { return new Error(t('common.mandatory')) } + if (r.tag.includes(' ')) { + invalidData.value &= ~validationFlags.content + return new Error(t('records.errors.hasSpace')) + } + return true } } diff --git a/web/src/locale/en-US.ts b/web/src/locale/en-US.ts index 50c7a29..21941bd 100644 --- a/web/src/locale/en-US.ts +++ b/web/src/locale/en-US.ts @@ -58,7 +58,7 @@ export default { }, records: { '_': 'Record', - name: 'Record Name', + name: 'Resource Record', recordType: 'Type', content: 'Record', search: 'Search...', @@ -83,8 +83,14 @@ export default { errors: { endWithDot: 'should end with a dot', + hasSpace: 'shoule have no space', badIPv4: 'invalid IPv4 address', badIPv6: 'invalid IPv6 address', + badName: { + dotAndMinus: 'should not start or end with "." "-"', + doubleDots: 'should have no contianus "."', + logerThan63: 'should not longer than 63 characters splited by "."' + } } } } \ No newline at end of file diff --git a/web/src/locale/zh-CN.ts b/web/src/locale/zh-CN.ts index f90cd6b..f7e0945 100644 --- a/web/src/locale/zh-CN.ts +++ b/web/src/locale/zh-CN.ts @@ -58,7 +58,7 @@ export default { }, records: { '_': '记录', - name: '记录名', + name: '资源记录', recordType: '类型', content: '记录值', search: '搜索...', @@ -83,8 +83,14 @@ export default { errors: { endWithDot: '应当以 . 结尾', + hasSpace: '不能有空格', badIPv4: '不是有效的 IPv4 地址', badIPv6: '不是有效的 IPv6 地址', + badName: { + dotAndMinus: '资源记录不能以 "."、"-" 开头或结尾', + doubleDots: '资源记录不能有连续的 "."', + logerThan63: '资源记录以 "." 分割的每个字符串长度不能超过63字符' + } } } } \ No newline at end of file