From f3dc16c72e87e70d2c543afcf2f2c3fd2c527f67 Mon Sep 17 00:00:00 2001 From: seaerchin <44049504+seaerchin@users.noreply.github.com> Date: Thu, 21 Mar 2024 13:15:34 +0800 Subject: [PATCH] fix(routeselector/resourceroom): remove accidental comments + fix typo (#1859) * fix(routeselector/resourceroom): remove accidental comments + fix typo * fix(routeselector): validate tou * fix(validators): add new regex * test(routeselector): remove old check + fix tests --- src/__tests__/RouteSelector.spec.jsx | 8 +++---- src/layouts/ResourceRoom/ResourceRoom.tsx | 2 +- src/routing/RouteSelector.jsx | 28 ++++++----------------- src/utils/validators.js | 5 ++++ 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/__tests__/RouteSelector.spec.jsx b/src/__tests__/RouteSelector.spec.jsx index 0cd9a7727..ea5a4b55e 100644 --- a/src/__tests__/RouteSelector.spec.jsx +++ b/src/__tests__/RouteSelector.spec.jsx @@ -384,7 +384,7 @@ describe("Tests for RouteSelector", () => { render( @@ -518,7 +518,7 @@ describe("Tests for RouteSelector", () => { test("Should render EditPage page for site site-name if logged in", () => { // Act render( - + @@ -656,7 +656,7 @@ describe("Tests for RouteSelector", () => { render( @@ -693,7 +693,7 @@ describe("Tests for RouteSelector", () => { render( diff --git a/src/layouts/ResourceRoom/ResourceRoom.tsx b/src/layouts/ResourceRoom/ResourceRoom.tsx index 502fea5fe..57a608019 100644 --- a/src/layouts/ResourceRoom/ResourceRoom.tsx +++ b/src/layouts/ResourceRoom/ResourceRoom.tsx @@ -386,7 +386,7 @@ const ResourceRoomContent = ({ > Resource room title { 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) - }, - }} - /> - - { 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)) }, }} /> @@ -107,7 +93,7 @@ export const RouteSelector = () => { ]} validate={{ subCollectionName: (value) => { - return !specialCharactersRegexTest.test(value) + return ALLOWED_CHARACTERS_REGEX.test(decodeURIComponent(value)) }, }} > @@ -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) ) }, }} diff --git a/src/utils/validators.js b/src/utils/validators.js index 288c254af..7cab88c03 100644 --- a/src/utils/validators.js +++ b/src/utils/validators.js @@ -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 = /[~%^?*+#./\\`;~{}[\]"<>]/