-
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: parse numbers correctly #1213
Conversation
LGTM |
perhaps stick a decimal in there for completeness, -0 is also an interesting case. |
From @thedufer's comment I was under the impression that coercing the number to a string should happen in |
7d0bc4e
to
a3e375d
Compare
Pushed new tests. Looking into the |
@kenany interesting. I think See the original commit: 422d3c9#diff-82accdcd8cb0f24f4b05d365c996d64fR22 It appears this passed through because |
The check for a number could be done at the top of |
Also, I'm not sure why converting the number to a string before passing it to the encoder function would cause a problem. Even if a custom encoder was being used, they should have already been supporting strings right? The only difference is that they get a string for numbers instead of a number now. |
Actually yeah the function's name is pretty clear that we should coerce in there :) |
@rvagg Thoughts? (and PTAL at the tests again) Technically, If we need to be safe, we can make @mscdex one would hope so. |
priority is to feature-match what was there before, don't go fixing other things in this, separate PR for that and separate consideration re semver-major this LGTM if @mscdex and others are on board |
To clarify: this fixes the behavior of |
@Fishrock123 I guess if we want to be absolutely 100% backwards compatible, we need to move the change from I have a hard time believing the current solution would actually affect anyone (for reasons I previously described). FWIW I actually just manually searched through ~1200 search results for EDIT: I also searched through another ~800 search results for |
ok, so what's it to be? I don't have a strong opinion beyond not making this a breaking change for people, it was supposed to be semver-patch so let's try and keep it that way -- internal changes with no external API change should be the goal. So fix |
I'm going to fix both in two commits, incoming momentarily. |
a3e375d
to
3ab2850
Compare
@@ -90,6 +90,9 @@ var hexTable = new Array(256); | |||
for (var i = 0; i < 256; ++i) | |||
hexTable[i] = '%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase(); | |||
QueryString.escape = function(str) { | |||
// replaces encodeURIComponent | |||
// http://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3.4 | |||
str = '' + 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 is what encodeURIComponent does on any input
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.
I'm fine with that, it looks like if it's already a string, there's no performance penalty involved.
lgtm, good work |
LGTM too. |
Fixes a number parsing regression introduced in 85a92a3 Fixes: nodejs#1208 PR-URL: nodejs#1213 Reviewed-By: Rod Vagg <[email protected]> Reviewed-By: Brian White <[email protected]>
stringifyPrimitive has always failed to stringify numbers since its introduction in 422d3c9. This went uncaught due to encodeURIComponent's string coercion. Fixes: nodejs#1208 PR-URL: nodejs#1213 Reviewed-By: Rod Vagg <[email protected]> Reviewed-By: Brian White <[email protected]>
3ab2850
to
c9aec2b
Compare
Notable Changes: * path: New type-checking on path.resolve() <#1153> uncovered some edge-cases being relied upon in the wild, most notably path.dirname(undefined). Type-checking has been loosened for path.dirname(), path.basename(), and path.extname(), (Colin Ihrig) <#1216>. * querystring: Internal optimizations in querystring.parse() and querystring.stringify() <#847> prevented Number literals from being properly converted via querystring.escape() <#1208>, exposing a blind-spot in the test suite. The bug and the tests have now been fixed (Jeremiah Senkpiel) <#1213>.
Fixes: #1208
I dunno if the test cases need to be any more thorough.
cc @rvagg @mscdex