-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
querystring: using toString for objects on querystring.escape #5341
Conversation
I just ran some quick benchmarks and it seems that using the |
@mscdex rewritten with typecheck |
Not quite.
|
@jacobp100 the same with
so the current solution is better than String constructor. Thank you for additional test case :) |
You’re correct, good catch. Just checked, per spec, |
LGTM |
Are there any cases we can test where this would make a difference even if you are not setting |
@Fishrock123 What do you mean? There will always be a |
Nah, he's right. If toString is not callable, then you need to try valueOf. If that's also not callable, you need to throw an error. |
Fixed. + more tests Seems like it is better to use |
@mscdex @nodejs/ctc ... ping |
if (typeof str !== 'string') { | ||
if (typeof str === 'object') | ||
str = String(str); | ||
else str += ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be moved to the next line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why? is there any reason to add empty string to str if it is already a string?
please check out tests below, maybe I forgot some cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I meant this as a style nit: moving the str += '';
to the next line instead of on the same line as the else
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh. will fix in 5 minutes, thank you
@mscdex your variant will fail for this test
and in my version there is no problem with encoding symbols - it will throw as with encodeURIComponent |
LGTM with one minor nit |
One failure in CI that looks unrelated. |
@mscdex ... any further comments on this one? |
@silentroach ... can you update the commit log to follow our style guidelines here: https://github.com/nodejs/node/blob/master/CONTRIBUTING.md#step-3-commit |
@jasnell Nope, other than commit message needs to be formatted correctly |
Yep, LGTM |
New CI, just to be extra careful ;-) https://ci.nodejs.org/job/node-test-pull-request/2244/ |
Landed in 5dafb43 |
Thank you :} |
querystring.encode
unexpected behavior on objects, see #5309here is specs for
encodeURIComponent
- http://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3.4, so object must be casted to string viatoString
, not viavalueOf
.Here is why: