-
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
1.6.0: querystring.stringify does not work with number literals #1208
Comments
85a92a3 appears to be at fault - |
this is bad. |
@mscdex @trevnorris pinging you since this is because of 85a92a3 |
This seems like something that there should have been an existing test for. |
Would this patch suffice? diff --git a/lib/querystring.js b/lib/querystring.js
index af320cf..601ed16 100644
--- a/lib/querystring.js
+++ b/lib/querystring.js
@@ -145,7 +145,7 @@ QueryString.escape = function(str) {
var stringifyPrimitive = function(v) {
if (typeof v === 'string' || (typeof v === 'number' && isFinite(v)))
- return v;
+ return String(v);
if (typeof v === 'boolean')
return v ? 'true' : 'false';
return '';
diff --git a/test/parallel/test-querystring.js b/test/parallel/test-querystring.js
index e2591d7..6ebb85e 100644
--- a/test/parallel/test-querystring.js
+++ b/test/parallel/test-querystring.js
@@ -14,6 +14,7 @@ var qsTestCases = [
['foo=bar', 'foo=bar', {'foo': 'bar'}],
['foo=bar&foo=quux', 'foo=bar&foo=quux', {'foo': ['bar', 'quux']}],
['foo=1&bar=2', 'foo=1&bar=2', {'foo': '1', 'bar': '2'}],
+ ['foo=1&bar=2', 'foo=1&bar=2', {'foo': 1, 'bar': 2}],
['my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F',
'my%20weird%20field=q1!2%22\'w%245%267%2Fz8)%3F',
{'my weird field': 'q1!2"\'w$5&7/z8)?' }], |
If we're so worried about optimizing this, it seems wrong to run strings through |
@thedufer Alright, diff --git a/lib/querystring.js b/lib/querystring.js
index af320cf..0a5e2d1 100644
--- a/lib/querystring.js
+++ b/lib/querystring.js
@@ -144,8 +144,10 @@ QueryString.escape = function(str) {
};
var stringifyPrimitive = function(v) {
- if (typeof v === 'string' || (typeof v === 'number' && isFinite(v)))
+ if (typeof v === 'string')
return v;
+ if (typeof v === 'number' && isFinite(v))
+ return String(v);
if (typeof v === 'boolean')
return v ? 'true' : 'false';
return ''; |
Looks like we should use |
Seems reasonable. However, this is dependent on the expectations of |
Looks like all the current querystring test cases are strings: https://github.com/iojs/io.js/blob/v1.x/test/parallel/test-querystring.js |
@Fishrock123 There doesn't seem to be a case where it passes a number. Try suggested test by @kenany above. |
Can someone get a PR in for this and we'll push a 1.6.1 today, @mscdex are you in a position to deal with this one or should someone else step up? |
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]>
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>.
1.5.1:
1.6.0:
The text was updated successfully, but these errors were encountered: