feat: restrict the allowed characters for slug

This commit is contained in:
DIYgod 2023-03-06 01:41:18 +00:00
parent 11fc759533
commit 8324beaa09
No known key found for this signature in database
2 changed files with 10 additions and 1 deletions

View File

@ -130,5 +130,6 @@
"Got it, thanks!" : "好的,谢谢!",
"Published!" : "已发布!",
"Title goes here...": "标题在这里...",
"Start writing...": "开始写作..."
"Start writing...": "开始写作...",
"Slug can only contain letters, numbers, hyphens, and underscores." : "短链接只能包含字母、数字、连字符和下划线。"
}

View File

@ -140,6 +140,14 @@ export default function SubdomainEditor() {
),
)
}
if (key === "slug" && !/^[a-zA-Z0-9\-_]*$/.test(value as string)) {
toast.error(
t(
"Slug can only contain letters, numbers, hyphens, and underscores.",
),
)
return
}
const newValues = { ...values, [key]: value }
if (draftKey) {
setStorage(draftKey, {