From c0c6caa9d5e0ec4523a3328becd20e4d6615eae3 Mon Sep 17 00:00:00 2001 From: dcshzj <27919917+dcshzj@users.noreply.github.com> Date: Sat, 16 Nov 2024 15:30:45 +0800 Subject: [PATCH] fix: escape dots in URLs --- packages/components/src/utils/__tests__/validation.test.ts | 2 ++ packages/components/src/utils/validation.ts | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/components/src/utils/__tests__/validation.test.ts b/packages/components/src/utils/__tests__/validation.test.ts index cf6531e7c..9c62b7417 100644 --- a/packages/components/src/utils/__tests__/validation.test.ts +++ b/packages/components/src/utils/__tests__/validation.test.ts @@ -147,6 +147,7 @@ describe("validation", () => { "https://www.example.com/embed/abcdefg", "https://www.another-site.com/watch?v=abcdefg", "https://youtu.be/dQw4w9WgXcQ", + "https://www.youtube.fakesite.com/watch?v=dQw4w9WgXcQ&feature=youtu.be", ] testCases.forEach((testCase) => { @@ -174,6 +175,7 @@ describe("validation", () => { const testCases = [ "https://www.example.com/maps/embed?pb=!1m18!1m12!1m3!1d3961.473373876674!2d103.8486973142665!3d1.3035969990313745!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x31da19b8b4c6e1e1%3A0x2f1f6b8f0a1b2a7d!2sMinistry%20of%20Communications%20and%20Information!5e0!3m2!1sen!2ssg!4v1632291134655!5m2!1en!2sg", "https://www.google.com/maps?pb=!1m18!1m12!1m3!1d3961.473373876674!2d103.8486973142665!3d1.3035969990313745!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x31da19b8b4c6e1e1%3A0x2f1f6b8f0a1b2a7d!2sMinistry%20of%20Communications%20and%20Information!5e0!3m2!1en!2sg!4v1632291134655!5m2!1en!2sg", + "https://www.google.fakesite.com/maps/embed?pb=!1m18!1m12!1m3!1d3961.473373876674!2d103.8486973142665!3d1.3035969990313745!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x31da19b8b4c6e1e1%3A0x2f1f6b8f0a1b2a7d!2sMinistry%20of%20Communications%20and%20Information!5e0!3m2!1sen!2ssg!4v1632291134655!5m2!1en!2sg", ] testCases.forEach((testCase) => { diff --git a/packages/components/src/utils/validation.ts b/packages/components/src/utils/validation.ts index 0cfb53e5a..5b112c93f 100644 --- a/packages/components/src/utils/validation.ts +++ b/packages/components/src/utils/validation.ts @@ -19,6 +19,7 @@ export const REF_HREF_PATTERN = `(${ALLOWED_URL_REGEXES.external})|(${ALLOWED_URL_REGEXES.internal})|(${ALLOWED_URL_REGEXES.files})|(${ALLOWED_URL_REGEXES.legacy})` as const export const YOUTUBE_URL_PATTERN = - "^https://www.(youtube|youtube-nocookie).com/(embed/|watch\\?v=).*$" + "^https://www\\.(youtube|youtube-nocookie)\\.com/(embed/|watch\\?v=).*$" -export const GOOGLE_MAPS_URL_PATTERN = "^https://www.google.com/maps/embed?.*$" +export const GOOGLE_MAPS_URL_PATTERN = + "^https://www\\.google\\.com/maps/embed?.*$"