Skip to content

Commit f58b904

Browse files
conico974Nicolas Dorseuil
and
Nicolas Dorseuil
authored
Encode customization header (#3289)
Co-authored-by: Nicolas Dorseuil <[email protected]>
1 parent d5992f1 commit f58b904

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

.changeset/lazy-pants-matter.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"gitbook-v2": patch
3+
"gitbook": patch
4+
---
5+
6+
encode customization header

packages/gitbook-v2/src/middleware.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ async function serveSiteRoutes(requestURL: URL, request: NextRequest) {
226226
const customization = siteRequestURL.searchParams.get('customization');
227227
if (customization && validateSerializedCustomization(customization)) {
228228
routeType = 'dynamic';
229-
requestHeaders.set(MiddlewareHeaders.Customization, customization);
229+
// We need to encode the customization headers, otherwise it will fail for some customization values containing non ASCII chars on vercel.
230+
requestHeaders.set(MiddlewareHeaders.Customization, encodeURIComponent(customization));
230231
}
231232
const theme = siteRequestURL.searchParams.get('theme');
232233
if (theme === CustomizationThemeMode.Dark || theme === CustomizationThemeMode.Light) {

packages/gitbook/src/lib/customization.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ export async function getDynamicCustomizationSettings(
1212
): Promise<SiteCustomizationSettings> {
1313
const headersList = await headers();
1414
const extend = headersList.get(MiddlewareHeaders.Customization);
15+
1516
if (extend) {
1617
try {
17-
const parsedSettings = rison.decode_object<SiteCustomizationSettings>(extend);
18+
// We need to decode it first as it is URL encoded, then decode the Rison object
19+
const unencoded = decodeURIComponent(extend);
20+
const parsedSettings = rison.decode_object<SiteCustomizationSettings>(unencoded);
1821

1922
return parsedSettings;
2023
} catch (_error) {}

packages/gitbook/src/middleware.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ export async function middleware(request: NextRequest) {
201201

202202
const customization = url.searchParams.get('customization');
203203
if (customization && validateSerializedCustomization(customization)) {
204-
headers.set(MiddlewareHeaders.Customization, customization);
204+
// We need to encode the customization to ensure it is properly encoded in vercel.
205+
// We do it here as well so that we have a single method to decode it later.
206+
headers.set(MiddlewareHeaders.Customization, encodeURIComponent(customization));
205207
}
206208

207209
const theme = url.searchParams.get('theme');

0 commit comments

Comments
 (0)