Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
41fd30ef
Commit
41fd30ef
authored
Jan 09, 2026
by
Jiachi Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update test
parent
b02ac1bd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
13 deletions
+15
-13
base-server.ts
packages/next/src/server/base-server.ts
+2
-0
middleware-non-ascii-headers.test.ts
...re-non-ascii-headers/middleware-non-ascii-headers.test.ts
+13
-13
No files found.
packages/next/src/server/base-server.ts
View file @
41fd30ef
...
@@ -946,6 +946,8 @@ export default abstract class Server<
...
@@ -946,6 +946,8 @@ export default abstract class Server<
// In minimal mode (Vercel), decode percent-encoded header values.
// In minimal mode (Vercel), decode percent-encoded header values.
// Middleware encodes non-ASCII characters for safe HTTP transport,
// Middleware encodes non-ASCII characters for safe HTTP transport,
// and we decode them here to restore the original values.
// and we decode them here to restore the original values.
// Note: decodeHeaderValue is safe - it only decodes valid percent-encoded
// sequences and returns the original value if decoding fails.
if
(
this
.
minimalMode
)
{
if
(
this
.
minimalMode
)
{
for
(
const
key
of
Object
.
keys
(
req
.
headers
))
{
for
(
const
key
of
Object
.
keys
(
req
.
headers
))
{
const
value
=
req
.
headers
[
key
]
const
value
=
req
.
headers
[
key
]
...
...
test/e2e/middleware-non-ascii-headers/middleware-non-ascii-headers.test.ts
View file @
41fd30ef
...
@@ -187,31 +187,31 @@ describe('Middleware Non-ASCII Headers', () => {
...
@@ -187,31 +187,31 @@ describe('Middleware Non-ASCII Headers', () => {
expect
(
headers
[
'x-city'
]).
toBe
(
'São Paulo'
)
expect
(
headers
[
'x-city'
]).
toBe
(
'São Paulo'
)
})
})
// Test for
LOCAL scenario: when headers are sent as proper Latin-1
(not Mojibake)
// Test for
headers that arrive as proper UTF-8
(not Mojibake)
//
This happens when:
//
In HTTP/2 environments (like Vercel deployment), headers are transmitted as UTF-8.
//
- A local proxy (nginx, etc.) adds headers with non-ASCII
//
When the server interprets UTF-8 bytes as Latin-1, we get Mojibake.
//
- Node.js fetch/http client sends headers (converts to Latin-1)
//
This test verifies that both scenarios work:
//
Unlike CDN scenario, these arrive as single-byte Latin-1, not UTF-8 Mojibake
//
- Local: UTF-8 headers might arrive as Mojibake (Node.js interprets as Latin-1)
it
(
'should handle Latin-1 encoded headers (local proxy scenario)'
,
async
()
=>
{
// - Deploy: UTF-8 headers arrive correctly or as Mojibake depending on transport
// When fetchViaHTTP sends "Montréal", it encodes as Latin-1:
it
(
'should handle UTF-8 encoded headers (proxy scenario)'
,
async
()
=>
{
//
"é" becomes single byte 0xE9 (not UTF-8's 0xC3 0xA9)
//
Send headers as Mojibake to simulate what happens when UTF-8 bytes
//
This simulates a local proxy adding headers
//
are interpreted as Latin-1 by the server (common in CDN/proxy scenarios)
const
res
=
await
fetchViaHTTP
(
const
res
=
await
fetchViaHTTP
(
next
.
url
,
next
.
url
,
'/api/headers'
,
'/api/headers'
,
{},
{},
{
{
headers
:
{
headers
:
{
'x-city'
:
'Montréal'
,
// Latin-1: é = 0xE9
'x-city'
:
toMojibake
(
'Montréal'
),
'x-region'
:
'Île-de-France'
,
'x-region'
:
toMojibake
(
'Île-de-France'
)
,
'x-country'
:
'Österreich'
,
'x-country'
:
toMojibake
(
'Österreich'
)
,
},
},
}
}
)
)
expect
(
res
.
status
).
toBe
(
200
)
expect
(
res
.
status
).
toBe
(
200
)
const
headers
=
await
res
.
json
()
const
headers
=
await
res
.
json
()
// These should be
preserv
ed correctly through middleware
// These should be
decod
ed correctly through middleware
expect
(
headers
[
'x-city'
]).
toBe
(
'Montréal'
)
expect
(
headers
[
'x-city'
]).
toBe
(
'Montréal'
)
expect
(
headers
[
'x-region'
]).
toBe
(
'Île-de-France'
)
expect
(
headers
[
'x-region'
]).
toBe
(
'Île-de-France'
)
expect
(
headers
[
'x-country'
]).
toBe
(
'Österreich'
)
expect
(
headers
[
'x-country'
]).
toBe
(
'Österreich'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment