Skip to content

Commit

Permalink
Use encodeURIComponent instead of encodeURI to build URI
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrucs committed Oct 28, 2024
1 parent dbc2dac commit 4284e8f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions frontend/src/components/pages/details/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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 = ({
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/pages/search/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}` : ''
}`;

Expand Down
8 changes: 4 additions & 4 deletions frontend/src/pages/sitemap.xml.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const getApiContentForLanguage = async (language: string): Promise<string> => {
const touristicContentUrls = touristicContents
.map(({ id, name }) =>
name && id
? `<url><loc>${baseUrl}/service/${id}-${encodeURI(
? `<url><loc>${baseUrl}/service/${id}-${encodeURIComponent(
convertStringForSitemap(name),
)}</loc></url>`
: '',
Expand All @@ -93,7 +93,7 @@ const getApiContentForLanguage = async (language: string): Promise<string> => {
const outdoorSitesUrls = outdoorSites
.map(({ id, name }) =>
name && id
? `<url><loc>${baseUrl}/outdoor-site/${id}-${encodeURI(
? `<url><loc>${baseUrl}/outdoor-site/${id}-${encodeURIComponent(
convertStringForSitemap(name),
)}</loc></url>`
: '',
Expand All @@ -106,7 +106,7 @@ const getApiContentForLanguage = async (language: string): Promise<string> => {
const outdoorCoursesUrls = outdoorCourses
.map(({ id, name }) =>
name && id
? `<url><loc>${baseUrl}/outdoor-course/${id}-${encodeURI(
? `<url><loc>${baseUrl}/outdoor-course/${id}-${encodeURIComponent(
convertStringForSitemap(name),
)}</loc></url>`
: '',
Expand All @@ -119,7 +119,7 @@ const getApiContentForLanguage = async (language: string): Promise<string> => {
external_url !== null && external_url.length > 0
? `<url><loc>${external_url}</loc></url>`
: title && id
? `<url><loc>${baseUrl}/information/${id}-${encodeURI(
? `<url><loc>${baseUrl}/information/${id}-${encodeURIComponent(
convertStringForSitemap(title),
)}</loc></url>`
: '',
Expand Down

0 comments on commit 4284e8f

Please sign in to comment.