[Next 9.5.4] [ERR_INVALID_CHAR]: Invalid character in header content ["Location"]
See original GitHub issueBug report
Describe the bug
internal server error occurs when redirect path includes query strings of non-ascii character(like Japanese).
in this PR, non-ascii character is passed to ‘Location’ header without encoding. https://github.com/vercel/next.js/pull/17323/files
To Reproduce
- Set
next.config.js
with trailing slash configtrue
.
<!-- next.config.js -->
module.exports = {
trailingSlash: true
};
- Open link with query strings of non-ascii character
<!-- indes.jsx -->
export default function IndexPage() {
return (
<div>
<a href="/about?tag=日本語">
with query strings
</a>
</div>
);
}
- Redirected to
/about?tag=日本語
page, not/about/?tag=日本語
. and 500 error occurs.
TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["Location"]
at ServerResponse.setHeader (_http_outgoing.js:488:3)
at Object.fn (/node_modules/next/next-server/server/next-server.ts:569:15)
at Router.execute (/node_modules/next/next-server/server/router.ts:200:40)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at DevServer.run (/node_modules/next/next-server/server/next-server.ts:855:23)
here is a demo. https://codesandbox.io/s/non-ascii-query-error-c8esl
Expected behavior
redirected to /about/?tag=日本語
, with trailing slash.
otherwise, encode japanese character.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:16
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Next.js bug: ERR_INVALID_CHAR Invalid character in header ...
Next. js bug: ERR_INVALID_CHAR Invalid character in header content ["Location"] - CodeSandbox.
Read more >How to fix: TypeError: Invalid character in header content ...
I am using Next.js, and I have a login page. When I use specific character such as š on username and write wrong...
Read more >Invalid character in header content ["Location"]
I'm getting this error message in the browser (500) when I click on logout. Deployed on vercel: https://next-auth-app-1.now.sh/ Invalid ...
Read more >TypeError: Invalid character in header content ["Authorization ...
this a exercise from Andrew Meads Complete node.js developer course, the problem seems to be on "set("Authorization",.... any idea how to ...
Read more >Response header name ' ' contains invalid characters ... - IBM
Response header name ' ' contains invalid characters, aborting request ... used to review the content of the HTTP request to find the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We encountered this problem when trying to redirect to a url with non-ascii characters
Our solution: wrap the non-ascii characters with
encodeURIComponent
. Done.This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.