querystring: Removing typecasting of numeric strings to numbers
authorMicheil Smith <micheil@brandedcode.com>
Mon, 19 Jul 2010 08:55:11 +0000 (18:55 +1000)
committerRyan Dahl <ry@tinyclouds.org>
Mon, 19 Jul 2010 18:07:08 +0000 (11:07 -0700)
The tests did not accurately test for a strict equality, meaning that the
number == to the string.

lib/querystring.js
test/simple/test-querystring.js

index f48ee58..ba2b1cc 100644 (file)
@@ -87,7 +87,6 @@ QueryString.parse = QueryString.decode = function (qs, sep, eq) {
       var end = offset + all.length == key.length;
       name = name || nameInBrackets || nameIn2Quotes || nameIn1Quotes;
       next = end ? value : {};
-      next = next && (+next == next ? +next : next);
       if (Array.isArray(res[name])) {
         res[name].push(next);
         res = next;
index b58c4f8..e159846 100644 (file)
@@ -2,26 +2,26 @@ common = require("../common");
 assert = common.assert;
 
 // test using assert
-
 var qs = require("querystring");
 
 // folding block.
 {
 // [ wonkyQS, canonicalQS, obj ]
 var qsTestCases = [
+  ["foo=918854443121279438895193", "foo=918854443121279438895193", {"foo": "918854443121279438895193"}],
   ["foo=bar",  "foo=bar", {"foo" : "bar"}],
   ["foo=bar&foo=quux", "foo%5B%5D=bar&foo%5B%5D=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)?" }],
   ["foo%3Dbaz=bar", "foo%3Dbaz=bar", {"foo=baz" : "bar"}],
   ["foo=baz=bar", "foo=baz%3Dbar", {"foo" : "baz=bar"}],
     [ "str=foo&arr[]=1&arr[]=2&arr[]=3&obj[a]=bar&obj[b][]=4&obj[b][]=5&obj[b][]=6&obj[b][]=&obj[c][]=4&obj[c][]=5&obj[c][][somestr]=baz&obj[objobj][objobjstr]=blerg&somenull=&undef=", "str=foo&arr%5B%5D=1&arr%5B%5D=2&arr%5B%5D=3&obj%5Ba%5D=bar&obj%5Bb%5D%5B%5D=4&obj%5Bb%5D%5B%5D=5&obj%5Bb%5D%5B%5D=6&obj%5Bb%5D%5B%5D=&obj%5Bc%5D%5B%5D=4&obj%5Bc%5D%5B%5D=5&obj%5Bc%5D%5B%5D%5Bsomestr%5D=baz&obj%5Bobjobj%5D%5Bobjobjstr%5D=blerg&somenull=&undef=", {
     "str":"foo",
-    "arr":[1,2,3],
+    "arr":["1","2","3"],
     "obj":{
       "a":"bar",
-      "b":[4,5,6,""],
-      "c":[4,5,{"somestr":"baz"}],
+      "b":["4","5","6",""],
+      "c":["4","5",{"somestr":"baz"}],
       "objobj":{"objobjstr":"blerg"}
     },
     "somenull":"",
@@ -65,8 +65,8 @@ var qsWeirdObjects = [
   [ {e:extendedFunction}, "e=", {"e":""} ],
   [ {d:new Date()}, "d=", {"d":""} ],
   [ {d:Date}, "d=", {"d":""} ],
-  [ {f:new Boolean(false), t:new Boolean(true)}, "f=0&t=1", {"f":0, "t":1} ],
-  [ {f:false, t:true}, "f=0&t=1", {"f":0, "t":1} ],
+  [ {f:new Boolean(false), t:new Boolean(true)}, "f=0&t=1", {"f":"0", "t":"1"} ],
+  [ {f:false, t:true}, "f=0&t=1", {"f":"0", "t":"1"} ],
   [ {n:null}, "n=", {"n":""} ],
   [ {nan:NaN}, "nan=", {"nan":""} ],
   [ {inf:Infinity}, "inf=", {"inf":""} ]
@@ -87,6 +87,8 @@ var qsNoMungeTestCases = [
   ["obj%5Btrololol%5D=yes&obj%5Blololo%5D=no", {"obj": {"trololol": "yes", "lololo": "no"}}]
 ];
 
+assert.strictEqual("918854443121279438895193", qs.parse("id=918854443121279438895193").id);
+
 // test that the canonical qs is parsed properly.
 qsTestCases.forEach(function (testCase) {
   assert.deepEqual(testCase[2], qs.parse(testCase[0]));