Skip to content

Commit

Permalink
fix(validators): add new regex
Browse files Browse the repository at this point in the history
  • Loading branch information
seaerchin committed Mar 20, 2024
1 parent 4f4be46 commit 13e0a71
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/routing/RouteSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { Workspace } from "layouts/Workspace"
import { ProtectedRouteWithProps } from "routing/ProtectedRouteWithProps"
import RedirectIfLoggedInRoute from "routing/RedirectIfLoggedInRoute"

import { specialCharactersRegexTest } from "utils"
import { ALLOWED_CHARACTERS_REGEX } from "utils"

import {
ApprovedReviewRedirect,
Expand Down Expand Up @@ -80,11 +80,11 @@ export const RouteSelector = () => {
const decodedName = decodeURIComponent(encodedName)
return (
value === "terms-of-use.md" ||
!specialCharactersRegexTest.test(decodedName)
ALLOWED_CHARACTERS_REGEX.test(decodedName)
)
},
subCollectionName: (value) => {
return !specialCharactersRegexTest.test(decodeURIComponent(value))
return ALLOWED_CHARACTERS_REGEX.test(decodeURIComponent(value))
},
}}
/>
Expand All @@ -96,7 +96,7 @@ export const RouteSelector = () => {
]}
validate={{
subCollectionName: (value) => {
return !specialCharactersRegexTest.test(decodeURIComponent(value))
return ALLOWED_CHARACTERS_REGEX.test(decodeURIComponent(value))
},
}}
>
Expand All @@ -120,8 +120,8 @@ export const RouteSelector = () => {
// NOTE: This value is prepended with either `files|images`
// and nested directories are separated by `/` as well.
const decodedValues = decodeURIComponent(value).split("/")
return decodedValues.every(
(val) => !specialCharactersRegexTest.test(val)
return decodedValues.every((val) =>
ALLOWED_CHARACTERS_REGEX.test(val)
)
},
}}
Expand Down
5 changes: 5 additions & 0 deletions src/utils/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export const fileNameExtensionRegexTest = /^[a-zA-z]{3,4}$/
export const RESOURCE_CATEGORY_REGEX = "^([a-zA-Z0-9]*[- ]?)+$"
export const slugifyLowerFalseRegexTest = /^([a-zA-Z0-9]+-)*[a-zA-Z0-9]+$/
export const resourceCategoryRegexTest = RegExp(RESOURCE_CATEGORY_REGEX)
// NOTE: This is a negation of the specialCharactersRegex
// and also allows for `-`.
// This is because of migration of pre-cms sites from github
// over to cms allows for dashes in the file/folder name.
export const ALLOWED_CHARACTERS_REGEX = /[^~%^*_+./\\`;~{}[\]"<>]/
export const specialCharactersRegexTest = /[~%^*_+\-./\\`;~{}[\]"<>]/
export const jekyllFirstCharacterRegexTest = /^[._#~]/
export const mediaSpecialCharactersRegexTest = /[~%^?*+#./\\`;~{}[\]"<>]/
Expand Down

0 comments on commit 13e0a71

Please sign in to comment.