Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The header content contains invalid characters TypeError: The header content contains invalid characters at ServerResponse. #3003

Closed
kimown opened this issue May 21, 2016 · 2 comments
Assignees
Milestone

Comments

@kimown
Copy link

kimown commented May 21, 2016

hi , today i upgrade my node version to 4.4.4 LTS, and i found something wrong in my old project.
the method i am using in my project

 res.redirect(`app.html?md=${url}`);

the url contains some chinese characters。
i find same error in github, http-party/node-http-proxy#964,
in nodejs/node@7bef1b7#diff-286202fdbdd74ede6f5f5334b6176b5cR298,
the commit add a method called _checkInvalidHeaderChar ,it will check the parameter.
when i am using res.redirect ,
image ,then the error occurs and my program exit.

i think setHeader should add try catch in https://github.com/expressjs/express/blob/master/lib/response.js#L1046 and
https://github.com/expressjs/express/blob/master/lib/response.js#L718

or using encodeURIComponent because i want to show title of the article in search bar.

res.redirect(`app.html?md=${encodeURIComponent(url)}`)
@dougwilson
Copy link
Contributor

Hi! res.redirect expects you to give it a URL, as such you would be responsible to call encodeURIComponent if that is necessary for your string.

@dougwilson dougwilson self-assigned this May 21, 2016
@dougwilson dougwilson added this to the 4.14 milestone Jun 14, 2016
@dougwilson
Copy link
Contributor

I know this is a semi-old issue, but the good news is that the underlying res.location will change in Express 4.14 to provide better behavior, including no longer throwing when you used your original code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants