@ -10,35 +10,17 @@ var qs = require("querystring");
var qsTestCases = [
var qsTestCases = [
[ "foo=918854443121279438895193" , "foo=918854443121279438895193" , { "foo" : "918854443121279438895193" } ] ,
[ "foo=918854443121279438895193" , "foo=918854443121279438895193" , { "foo" : "918854443121279438895193" } ] ,
[ "foo=bar" , "foo=bar" , { "foo" : "bar" } ] ,
[ "foo=bar" , "foo=bar" , { "foo" : "bar" } ] ,
[ "foo=bar&foo=quux" , "foo%5B%5D =bar&foo%5B%5D =quux" , { "foo" : [ "bar" , "quux" ] } ] ,
[ "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)?" } ] ,
[ "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%3Dbaz=bar" , "foo%3Dbaz=bar" , { "foo=baz" : "bar" } ] ,
[ "foo=baz=bar" , "foo=baz%3Dbar" , { "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&arr=2&arr=3&somenull=&undef=" , "str=foo&arr=1&arr=2&arr=3&somenull=&undef=" , {
"str" : "foo" ,
"str" : "foo" ,
"arr" : [ "1" , "2" , "3" ] ,
"arr" : [ "1" , "2" , "3" ] ,
"obj" : {
"a" : "bar" ,
"b" : [ "4" , "5" , "6" , "" ] ,
"c" : [ "4" , "5" , { "somestr" : "baz" } ] ,
"objobj" : { "objobjstr" : "blerg" }
} ,
"somenull" : "" ,
"somenull" : "" ,
"undef" : ""
"undef" : ""
} ] ,
} ] ,
[ "foo[bar][bla]=baz&foo[bar][bla]=blo" , "foo%5Bbar%5D%5Bbla%5D%5B%5D=baz&foo%5Bbar%5D%5Bbla%5D%5B%5D=blo" , { "foo" : { "bar" : { "bla" : [ "baz" , "blo" ] } } } ] ,
[ "foo[bar][][bla]=baz&foo[bar][][bla]=blo" , "foo%5Bbar%5D%5B%5D%5Bbla%5D=baz&foo%5Bbar%5D%5B%5D%5Bbla%5D=blo" , { "foo" : { "bar" : [ { "bla" : "baz" } , { "bla" : "blo" } ] } } ] ,
[ "foo[bar][bla][]=baz&foo[bar][bla][]=blo" , "foo%5Bbar%5D%5Bbla%5D%5B%5D=baz&foo%5Bbar%5D%5Bbla%5D%5B%5D=blo" , { "foo" : { "bar" : { "bla" : [ "baz" , "blo" ] } } } ] ,
[ "foo.bar.bla=baz&foo.bar.bla=blo" , "foo%5Bbar%5D%5Bbla%5D%5B%5D=baz&foo%5Bbar%5D%5Bbla%5D%5B%5D=blo" , { "foo" : { "bar" : { "bla" : [ "baz" , "blo" ] } } } ] ,
[ "foo.bar[].bla=baz&foo[bar][][bla]=blo" , "foo%5Bbar%5D%5B%5D%5Bbla%5D=baz&foo%5Bbar%5D%5B%5D%5Bbla%5D=blo" , { "foo" : { "bar" : [ { "bla" : "baz" } , { "bla" : "blo" } ] } } ] ,
[ "foo[bar].bla[]=baz&foo.bar[bla][]=blo" , "foo%5Bbar%5D%5Bbla%5D%5B%5D=baz&foo%5Bbar%5D%5Bbla%5D%5B%5D=blo" , { "foo" : { "bar" : { "bla" : [ "baz" , "blo" ] } } } ] ,
[ "foo['bar']['bla']=baz&foo[\"bar\"][\"bla\"]=blo" , "foo%5Bbar%5D%5Bbla%5D%5B%5D=baz&foo%5Bbar%5D%5Bbla%5D%5B%5D=blo" , { "foo" : { "bar" : { "bla" : [ "baz" , "blo" ] } } } ] ,
[ "foo['bar'][]['bla']=baz&foo['bar'][][\"bla\"]=blo" , "foo%5Bbar%5D%5B%5D%5Bbla%5D=baz&foo%5Bbar%5D%5B%5D%5Bbla%5D=blo" , { "foo" : { "bar" : [ { "bla" : "baz" } , { "bla" : "blo" } ] } } ] ,
[ "foo[bar][\"bla\"][]=baz&foo[\"bar\"][bla][]=blo" , "foo%5Bbar%5D%5Bbla%5D%5B%5D=baz&foo%5Bbar%5D%5Bbla%5D%5B%5D=blo" , { "foo" : { "bar" : { "bla" : [ "baz" , "blo" ] } } } ] ,
[ " foo = bar " , "%20foo%20=%20bar%20" , { " foo " : " bar " } ] ,
[ " foo = bar " , "%20foo%20=%20bar%20" , { " foo " : " bar " } ] ,
[ "foo=%zx" , "foo=%25zx" , { "foo" : "%zx" } ] ,
[ "foo=%zx" , "foo=%25zx" , { "foo" : "%zx" } ] ,
[ "foo=%EF%BF%BD" , "foo=%EF%BF%BD" , { "foo" : "\ufffd" } ]
[ "foo=%EF%BF%BD" , "foo=%EF%BF%BD" , { "foo" : "\ufffd" } ]
@ -47,7 +29,7 @@ var qsTestCases = [
// [ wonkyQS, canonicalQS, obj ]
// [ wonkyQS, canonicalQS, obj ]
var qsColonTestCases = [
var qsColonTestCases = [
[ "foo:bar" , "foo:bar" , { "foo" : "bar" } ] ,
[ "foo:bar" , "foo:bar" , { "foo" : "bar" } ] ,
[ "foo:bar;foo:quux" , "foo%5B%5D :bar;foo%5B%5D :quux" , { "foo" : [ "bar" , "quux" ] } ] ,
[ "foo:bar;foo:quux" , "foo:bar;foo:quux" , { "foo" : [ "bar" , "quux" ] } ] ,
[ "foo:1&bar:2;baz:quux" , "foo:1%26bar%3A2;baz:quux" , { "foo" : "1&bar:2" , "baz" : "quux" } ] ,
[ "foo:1&bar:2;baz:quux" , "foo:1%26bar%3A2;baz:quux" , { "foo" : "1&bar:2" , "baz" : "quux" } ] ,
[ "foo%3Abaz:bar" , "foo%3Abaz:bar" , { "foo:baz" : "bar" } ] ,
[ "foo%3Abaz:bar" , "foo%3Abaz:bar" , { "foo:baz" : "bar" } ] ,
[ "foo:baz:bar" , "foo:baz%3Abar" , { "foo" : "baz:bar" } ]
[ "foo:baz:bar" , "foo:baz%3Abar" , { "foo" : "baz:bar" } ]
@ -65,8 +47,8 @@ var qsWeirdObjects = [
[ { e : extendedFunction } , "e=" , { "e" : "" } ] ,
[ { e : extendedFunction } , "e=" , { "e" : "" } ] ,
[ { d : new Date ( ) } , "d=" , { "d" : "" } ] ,
[ { d : new Date ( ) } , "d=" , { "d" : "" } ] ,
[ { d : Date } , "d=" , { "d" : "" } ] ,
[ { d : Date } , "d=" , { "d" : "" } ] ,
[ { f : new Boolean ( false ) , t : new Boolean ( true ) } , "f=0 &t=1 " , { "f" : "0 " , "t" : "1 " } ] ,
[ { f : new Boolean ( false ) , t : new Boolean ( true ) } , "f=&t=" , { "f" : "" , "t" : "" } ] ,
[ { f : false , t : true } , "f=0&t=1 " , { "f" : "0 " , "t" : "1 " } ] ,
[ { f : false , t : true } , "f=false&t=true " , { "f" : "false " , "t" : "true " } ] ,
[ { n : null } , "n=" , { "n" : "" } ] ,
[ { n : null } , "n=" , { "n" : "" } ] ,
[ { nan : NaN } , "nan=" , { "nan" : "" } ] ,
[ { nan : NaN } , "nan=" , { "nan" : "" } ] ,
[ { inf : Infinity } , "inf=" , { "inf" : "" } ]
[ { inf : Infinity } , "inf=" , { "inf" : "" } ]
@ -84,7 +66,7 @@ var qsNoMungeTestCases = [
[ "gragh=1&gragh=3&goo=2" , { "gragh" : [ "1" , "3" ] , "goo" : "2" } ] ,
[ "gragh=1&gragh=3&goo=2" , { "gragh" : [ "1" , "3" ] , "goo" : "2" } ] ,
[ "frappucino=muffin&goat%5B%5D=scone&pond=moose" ,
[ "frappucino=muffin&goat%5B%5D=scone&pond=moose" ,
{ "frappucino" : "muffin" , "goat[]" : "scone" , "pond" : "moose" } ] ,
{ "frappucino" : "muffin" , "goat[]" : "scone" , "pond" : "moose" } ] ,
[ "obj%5B trololol%5D =yes&obj%5B lololo%5D =no" , { "obj" : { "trololol" : "yes" , "lololo" : "no" } } ]
[ "trololol=yes&lololo=no" , { "trololol" : "yes" , "lololo" : "no" } ]
] ;
] ;
assert . strictEqual ( "918854443121279438895193" , qs . parse ( "id=918854443121279438895193" ) . id ) ;
assert . strictEqual ( "918854443121279438895193" , qs . parse ( "id=918854443121279438895193" ) . id ) ;
@ -123,11 +105,6 @@ qsNoMungeTestCases.forEach(function (testCase) {
} ) ( ) ;
} ) ( ) ;
// now test stringifying
// now test stringifying
assert . throws ( function ( ) {
var f = { } ;
f . f = f ;
qs . stringify ( f ) ;
} ) ;
// basic
// basic
qsTestCases . forEach ( function ( testCase ) {
qsTestCases . forEach ( function ( testCase ) {