From 4284e8f17993b44d837eabd7de6fff89710f48b4 Mon Sep 17 00:00:00 2001 From: Florian Sommariva <1926041+dtrucs@users.noreply.github.com> Date: Thu, 24 Oct 2024 16:59:49 +0200 Subject: [PATCH] Use encodeURIComponent instead of encodeURI to build URI --- frontend/src/components/pages/details/utils.tsx | 10 +++++----- frontend/src/components/pages/search/utils.ts | 2 +- frontend/src/pages/sitemap.xml.tsx | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/pages/details/utils.tsx b/frontend/src/components/pages/details/utils.tsx index 23b0bd65b..ec50f3133 100644 --- a/frontend/src/components/pages/details/utils.tsx +++ b/frontend/src/components/pages/details/utils.tsx @@ -27,22 +27,22 @@ export const generateChildrenDetailsUrl = ( export const generateTouristicContentUrl = (id: number | string, title: string): string => { const titleWithNoSpace = convertStringForSitemap(title); - return `${routes.TOURISTIC_CONTENT}/${id}-${encodeURI(titleWithNoSpace)}`; + return `${routes.TOURISTIC_CONTENT}/${id}-${encodeURIComponent(titleWithNoSpace)}`; }; export const generateOutdoorSiteUrl = (id: number | string, title: string): string => { const titleWithNoSpace = convertStringForSitemap(title); - return `${routes.OUTDOOR_SITE}/${id}-${encodeURI(titleWithNoSpace)}`; + return `${routes.OUTDOOR_SITE}/${id}-${encodeURIComponent(titleWithNoSpace)}`; }; export const generateOutdoorCourseUrl = (id: number | string, title: string): string => { const titleWithNoSpace = convertStringForSitemap(title); - return `${routes.OUTDOOR_COURSE}/${id}-${encodeURI(titleWithNoSpace)}`; + return `${routes.OUTDOOR_COURSE}/${id}-${encodeURIComponent(titleWithNoSpace)}`; }; export const generateTouristicEventUrl = (id: number | string, title: string): string => { const titleWithNoSpace = convertStringForSitemap(title); - return `${routes.TOURISTIC_EVENT}/${id}-${encodeURI(titleWithNoSpace)}`; + return `${routes.TOURISTIC_EVENT}/${id}-${encodeURIComponent(titleWithNoSpace)}`; }; export const generateDetailsUrlFromType = ( @@ -53,7 +53,7 @@ export const generateDetailsUrlFromType = ( ): string => { const searchParams = params ? `?${new URLSearchParams(params).toString()}` : ''; const titleWithNoSpace = convertStringForSitemap(title); - return `${routes[type]}/${id}-${encodeURI(titleWithNoSpace)}${searchParams}`; + return `${routes[type]}/${id}-${encodeURIComponent(titleWithNoSpace)}${searchParams}`; }; export const templatesVariablesAreDefinedAndUsed = ({ diff --git a/frontend/src/components/pages/search/utils.ts b/frontend/src/components/pages/search/utils.ts index 38981e747..8911a5e0d 100644 --- a/frontend/src/components/pages/search/utils.ts +++ b/frontend/src/components/pages/search/utils.ts @@ -79,7 +79,7 @@ export const generateResultDetailsUrl = ( parentId?: number, ): string => { const titleWithNoSpace = convertStringForSitemap(title); - const detailsPageUrl = `${route}/${encodeURIComponent(id)}-${encodeURI(titleWithNoSpace)}${ + const detailsPageUrl = `${route}/${encodeURIComponent(id)}-${encodeURIComponent(titleWithNoSpace)}${ parentId ? `?parentId=${parentId}` : '' }`; diff --git a/frontend/src/pages/sitemap.xml.tsx b/frontend/src/pages/sitemap.xml.tsx index 2986ad767..9e63b880a 100644 --- a/frontend/src/pages/sitemap.xml.tsx +++ b/frontend/src/pages/sitemap.xml.tsx @@ -80,7 +80,7 @@ const getApiContentForLanguage = async (language: string): Promise => { const touristicContentUrls = touristicContents .map(({ id, name }) => name && id - ? `${baseUrl}/service/${id}-${encodeURI( + ? `${baseUrl}/service/${id}-${encodeURIComponent( convertStringForSitemap(name), )}` : '', @@ -93,7 +93,7 @@ const getApiContentForLanguage = async (language: string): Promise => { const outdoorSitesUrls = outdoorSites .map(({ id, name }) => name && id - ? `${baseUrl}/outdoor-site/${id}-${encodeURI( + ? `${baseUrl}/outdoor-site/${id}-${encodeURIComponent( convertStringForSitemap(name), )}` : '', @@ -106,7 +106,7 @@ const getApiContentForLanguage = async (language: string): Promise => { const outdoorCoursesUrls = outdoorCourses .map(({ id, name }) => name && id - ? `${baseUrl}/outdoor-course/${id}-${encodeURI( + ? `${baseUrl}/outdoor-course/${id}-${encodeURIComponent( convertStringForSitemap(name), )}` : '', @@ -119,7 +119,7 @@ const getApiContentForLanguage = async (language: string): Promise => { external_url !== null && external_url.length > 0 ? `${external_url}` : title && id - ? `${baseUrl}/information/${id}-${encodeURI( + ? `${baseUrl}/information/${id}-${encodeURIComponent( convertStringForSitemap(title), )}` : '',