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 all 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
8 changes: 4 additions & 4 deletions src/__tests__/RouteSelector.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ describe("Tests for RouteSelector", () => {
render(
<MemoryRouter
initialEntries={[
"/sites/site-name/resourceRoom/my-resource/resourceCategory/my-category/editPage/my-file",
"/sites/site-name/resourceRoom/my-resource/resourceCategory/my-category/editPage/my-file.md",
]}
>
<LoggedInContextProvider>
Expand Down Expand Up @@ -518,7 +518,7 @@ describe("Tests for RouteSelector", () => {
test("Should render EditPage page for site site-name if logged in", () => {
// Act
render(
<MemoryRouter initialEntries={["/sites/site-name/editPage/my-file"]}>
<MemoryRouter initialEntries={["/sites/site-name/editPage/my-file.md"]}>
<LoggedInContextProvider>
<RouteSelector />
</LoggedInContextProvider>
Expand Down Expand Up @@ -656,7 +656,7 @@ describe("Tests for RouteSelector", () => {
render(
<MemoryRouter
initialEntries={[
"/sites/site-name/folders/my-folder/editPage/my-file",
"/sites/site-name/folders/my-folder/editPage/my-file.md",
]}
>
<LoggedInContextProvider>
Expand Down Expand Up @@ -693,7 +693,7 @@ describe("Tests for RouteSelector", () => {
render(
<MemoryRouter
initialEntries={[
"/sites/site-name/folders/my-folder/subfolders/my%20subfolder/editPage/my-file",
"/sites/site-name/folders/my-folder/subfolders/my%20subfolder/editPage/my-file.md",
]}
>
<LoggedInContextProvider>
Expand Down
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
28 changes: 7 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,11 @@ export const RouteSelector = () => {
validate={{
fileName: (value) => {
const encodedName = value.split(".").slice(0, -1).join(".")
return !specialCharactersRegexTest.test(encodedName)
const decodedName = decodeURIComponent(encodedName)
return ALLOWED_CHARACTERS_REGEX.test(decodedName)
},
subCollectionName: (value) => {
return !specialCharactersRegexTest.test(value)
return ALLOWED_CHARACTERS_REGEX.test(decodeURIComponent(value))
},
}}
/>
Expand All @@ -107,7 +93,7 @@ export const RouteSelector = () => {
]}
validate={{
subCollectionName: (value) => {
return !specialCharactersRegexTest.test(value)
return ALLOWED_CHARACTERS_REGEX.test(decodeURIComponent(value))
},
}}
>
Expand All @@ -131,8 +117,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