Skip to content

Commit

Permalink
fix: escape dots in URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
dcshzj committed Nov 16, 2024
1 parent 63d2148 commit c0c6caa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/components/src/utils/__tests__/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down
5 changes: 3 additions & 2 deletions packages/components/src/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?.*$"

0 comments on commit c0c6caa

Please sign in to comment.