Skip to content

Commit e89a0d1

Browse files
author
Nicolas Dorseuil
committed
review fix
1 parent 2c612b7 commit e89a0d1

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

packages/open-next/src/core/routing/cacheInterceptor.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,21 @@ async function generateResult(
129129
},
130130
};
131131
}
132+
133+
/**
134+
*
135+
* https://github.com/vercel/next.js/blob/34039551d2e5f611c0abde31a197d9985918adaf/packages/next/src/shared/lib/router/utils/escape-path-delimiters.ts#L2-L10
136+
*/
137+
function escapePathDelimiters(
138+
segment: string,
139+
escapeEncoded?: boolean,
140+
): string {
141+
return segment.replace(
142+
new RegExp(`([/#?]${escapeEncoded ? "|%(2f|23|3f|5c)" : ""})`, "gi"),
143+
(char: string) => encodeURIComponent(char),
144+
);
145+
}
146+
132147
/**
133148
*
134149
* SSG cache key needs to be decoded, but some characters needs to be properly escaped
@@ -139,11 +154,7 @@ function decodePathParams(pathname: string): string {
139154
.split("/")
140155
.map((segment) => {
141156
try {
142-
// https://github.com/vercel/next.js/blob/34039551d2e5f611c0abde31a197d9985918adaf/packages/next/src/shared/lib/router/utils/escape-path-delimiters.ts#L2-L10
143-
return decodeURIComponent(segment).replace(
144-
/([\/#?]|%(2f|23|3f|5c))/gi,
145-
(char: string) => encodeURIComponent(char),
146-
);
157+
return escapePathDelimiters(decodeURIComponent(segment), true);
147158
} catch (e) {
148159
// If decodeURIComponent fails, we return the original segment
149160
return segment;

0 commit comments

Comments
 (0)