Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(routeselector/resourceroom): remove accidental comments + fix typo #1859

Merged
merged 4 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/layouts/ResourceRoom/ResourceRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ const ResourceRoomContent = ({
>
<FormLabel>Resource room title</FormLabel>
<Input
placeholder="New resource oom name"
placeholder="New resource room name"
{...register("newDirectoryName", {
required:
"Please ensure that you have entered a resource room name!",
Expand Down
31 changes: 10 additions & 21 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 @@ -69,21 +69,6 @@ export const RouteSelector = () => {
exact
path={[
"/sites/:siteName([a-zA-Z0-9-]+)/resourceRoom/:resourceRoomName([a-zA-Z0-9-]+)/resourceCategory/:resourceCategoryName([a-zA-Z0-9-]+)/editPage/:fileName",
]}
component={injectApprovalRedirect(EditPage)}
validate={{
fileName: (value) => {
const encodedName = value.split(".").slice(0, -1).join(".")
return !specialCharactersRegexTest.test(encodedName)
},
}}
/>

<ProtectedRouteWithProps
exact
path={[
// Collection is correct
// Subcollection disallows a few special characters
"/sites/:siteName([a-zA-Z0-9-]+)/folders/:collectionName([a-zA-Z0-9-]+)/subfolders/:subCollectionName/editPage/:fileName",
"/sites/:siteName([a-zA-Z0-9-]+)/folders/:collectionName([a-zA-Z0-9-]+)/editPage/:fileName",
Comment on lines 72 to 73
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking, do we not need to check subCollectionName?

"/sites/:siteName([a-zA-Z0-9-]+)/editPage/:fileName",
Expand All @@ -92,10 +77,14 @@ export const RouteSelector = () => {
validate={{
fileName: (value) => {
const encodedName = value.split(".").slice(0, -1).join(".")
return !specialCharactersRegexTest.test(encodedName)
const decodedName = decodeURIComponent(encodedName)
return (
value === "terms-of-use.md" ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this custom check for terms-of-use now

ALLOWED_CHARACTERS_REGEX.test(decodedName)
)
},
subCollectionName: (value) => {
return !specialCharactersRegexTest.test(value)
return ALLOWED_CHARACTERS_REGEX.test(decodeURIComponent(value))
},
}}
/>
Expand All @@ -107,7 +96,7 @@ export const RouteSelector = () => {
]}
validate={{
subCollectionName: (value) => {
return !specialCharactersRegexTest.test(value)
return ALLOWED_CHARACTERS_REGEX.test(decodeURIComponent(value))
},
}}
>
Expand All @@ -131,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
Loading