Skip to content

Commit 008a52d

Browse files
authored
fix(templates): URI encode the cacheTag in getMediaUrl utility - Website template (#13558)
### What? Encode the cacheTag in the ImageMedia component ### Why? In the website template, media is render using the updatedAt field as a cacheTag, this value causes an InvalidQueryStringException when deploying to Cloudfront ### How? Uses encodeURIComponent on encode the date value of updatedAt Fixes #13557
1 parent 7e98fbf commit 008a52d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

templates/website/src/utilities/getMediaUrl.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import { getClientSideURL } from '@/utilities/getURL'
99
export const getMediaUrl = (url: string | null | undefined, cacheTag?: string | null): string => {
1010
if (!url) return ''
1111

12+
if (cacheTag && cacheTag !== '') {
13+
cacheTag = encodeURIComponent(cacheTag)
14+
}
15+
1216
// Check if URL already has http/https protocol
1317
if (url.startsWith('http://') || url.startsWith('https://')) {
1418
return cacheTag ? `${url}?${cacheTag}` : url

templates/with-vercel-website/src/utilities/getMediaUrl.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import { getClientSideURL } from '@/utilities/getURL'
99
export const getMediaUrl = (url: string | null | undefined, cacheTag?: string | null): string => {
1010
if (!url) return ''
1111

12+
if (cacheTag && cacheTag !== '') {
13+
cacheTag = encodeURIComponent(cacheTag)
14+
}
15+
1216
// Check if URL already has http/https protocol
1317
if (url.startsWith('http://') || url.startsWith('https://')) {
1418
return cacheTag ? `${url}?${cacheTag}` : url

0 commit comments

Comments
 (0)