[hotfix] Ignore type checking for edge
[platform/framework/web/wrtjs.git] / device_home / node_modules / qs / test / parse.js
1 "use strict";var test=require("tape"),qs=require("../"),utils=require("../lib/utils"),iconv=require("iconv-lite"),SaferBuffer=require("safer-buffer").Buffer;test("parse()",(function(e){e.test("parses a simple string",(function(e){e.deepEqual(qs.parse("0=foo"),{0:"foo"}),e.deepEqual(qs.parse("foo=c++"),{foo:"c  "}),e.deepEqual(qs.parse("a[>=]=23"),{a:{">=":"23"}}),e.deepEqual(qs.parse("a[<=>]==23"),{a:{"<=>":"=23"}}),e.deepEqual(qs.parse("a[==]=23"),{a:{"==":"23"}}),e.deepEqual(qs.parse("foo",{strictNullHandling:!0}),{foo:null}),e.deepEqual(qs.parse("foo"),{foo:""}),e.deepEqual(qs.parse("foo="),{foo:""}),e.deepEqual(qs.parse("foo=bar"),{foo:"bar"}),e.deepEqual(qs.parse(" foo = bar = baz "),{" foo ":" bar = baz "}),e.deepEqual(qs.parse("foo=bar=baz"),{foo:"bar=baz"}),e.deepEqual(qs.parse("foo=bar&bar=baz"),{foo:"bar",bar:"baz"}),e.deepEqual(qs.parse("foo2=bar2&baz2="),{foo2:"bar2",baz2:""}),e.deepEqual(qs.parse("foo=bar&baz",{strictNullHandling:!0}),{foo:"bar",baz:null}),e.deepEqual(qs.parse("foo=bar&baz"),{foo:"bar",baz:""}),e.deepEqual(qs.parse("cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World"),{cht:"p3",chd:"t:60,40",chs:"250x100",chl:"Hello|World"}),e.end()})),e.test("allows enabling dot notation",(function(e){e.deepEqual(qs.parse("a.b=c"),{"a.b":"c"}),e.deepEqual(qs.parse("a.b=c",{allowDots:!0}),{a:{b:"c"}}),e.end()})),e.deepEqual(qs.parse("a[b]=c"),{a:{b:"c"}},"parses a single nested string"),e.deepEqual(qs.parse("a[b][c]=d"),{a:{b:{c:"d"}}},"parses a double nested string"),e.deepEqual(qs.parse("a[b][c][d][e][f][g][h]=i"),{a:{b:{c:{d:{e:{f:{"[g][h]":"i"}}}}}}},"defaults to a depth of 5"),e.test("only parses one level when depth = 1",(function(e){e.deepEqual(qs.parse("a[b][c]=d",{depth:1}),{a:{b:{"[c]":"d"}}}),e.deepEqual(qs.parse("a[b][c][d]=e",{depth:1}),{a:{b:{"[c][d]":"e"}}}),e.end()})),e.deepEqual(qs.parse("a=b&a=c"),{a:["b","c"]},"parses a simple array"),e.test("parses an explicit array",(function(e){e.deepEqual(qs.parse("a[]=b"),{a:["b"]}),e.deepEqual(qs.parse("a[]=b&a[]=c"),{a:["b","c"]}),e.deepEqual(qs.parse("a[]=b&a[]=c&a[]=d"),{a:["b","c","d"]}),e.end()})),e.test("parses a mix of simple and explicit arrays",(function(e){e.deepEqual(qs.parse("a=b&a[]=c"),{a:["b","c"]}),e.deepEqual(qs.parse("a[]=b&a=c"),{a:["b","c"]}),e.deepEqual(qs.parse("a[0]=b&a=c"),{a:["b","c"]}),e.deepEqual(qs.parse("a=b&a[0]=c"),{a:["b","c"]}),e.deepEqual(qs.parse("a[1]=b&a=c",{arrayLimit:20}),{a:["b","c"]}),e.deepEqual(qs.parse("a[]=b&a=c",{arrayLimit:0}),{a:["b","c"]}),e.deepEqual(qs.parse("a[]=b&a=c"),{a:["b","c"]}),e.deepEqual(qs.parse("a=b&a[1]=c",{arrayLimit:20}),{a:["b","c"]}),e.deepEqual(qs.parse("a=b&a[]=c",{arrayLimit:0}),{a:["b","c"]}),e.deepEqual(qs.parse("a=b&a[]=c"),{a:["b","c"]}),e.end()})),e.test("parses a nested array",(function(e){e.deepEqual(qs.parse("a[b][]=c&a[b][]=d"),{a:{b:["c","d"]}}),e.deepEqual(qs.parse("a[>=]=25"),{a:{">=":"25"}}),e.end()})),e.test("allows to specify array indices",(function(e){e.deepEqual(qs.parse("a[1]=c&a[0]=b&a[2]=d"),{a:["b","c","d"]}),e.deepEqual(qs.parse("a[1]=c&a[0]=b"),{a:["b","c"]}),e.deepEqual(qs.parse("a[1]=c",{arrayLimit:20}),{a:["c"]}),e.deepEqual(qs.parse("a[1]=c",{arrayLimit:0}),{a:{1:"c"}}),e.deepEqual(qs.parse("a[1]=c"),{a:["c"]}),e.end()})),e.test("limits specific array indices to arrayLimit",(function(e){e.deepEqual(qs.parse("a[20]=a",{arrayLimit:20}),{a:["a"]}),e.deepEqual(qs.parse("a[21]=a",{arrayLimit:20}),{a:{21:"a"}}),e.end()})),e.deepEqual(qs.parse("a[12b]=c"),{a:{"12b":"c"}},"supports keys that begin with a number"),e.test("supports encoded = signs",(function(e){e.deepEqual(qs.parse("he%3Dllo=th%3Dere"),{"he=llo":"th=ere"}),e.end()})),e.test("is ok with url encoded strings",(function(e){e.deepEqual(qs.parse("a[b%20c]=d"),{a:{"b c":"d"}}),e.deepEqual(qs.parse("a[b]=c%20d"),{a:{b:"c d"}}),e.end()})),e.test("allows brackets in the value",(function(e){e.deepEqual(qs.parse('pets=["tobi"]'),{pets:'["tobi"]'}),e.deepEqual(qs.parse('operators=[">=", "<="]'),{operators:'[">=", "<="]'}),e.end()})),e.test("allows empty values",(function(e){e.deepEqual(qs.parse(""),{}),e.deepEqual(qs.parse(null),{}),e.deepEqual(qs.parse(void 0),{}),e.end()})),e.test("transforms arrays to objects",(function(e){e.deepEqual(qs.parse("foo[0]=bar&foo[bad]=baz"),{foo:{0:"bar",bad:"baz"}}),e.deepEqual(qs.parse("foo[bad]=baz&foo[0]=bar"),{foo:{bad:"baz",0:"bar"}}),e.deepEqual(qs.parse("foo[bad]=baz&foo[]=bar"),{foo:{bad:"baz",0:"bar"}}),e.deepEqual(qs.parse("foo[]=bar&foo[bad]=baz"),{foo:{0:"bar",bad:"baz"}}),e.deepEqual(qs.parse("foo[bad]=baz&foo[]=bar&foo[]=foo"),{foo:{bad:"baz",0:"bar",1:"foo"}}),e.deepEqual(qs.parse("foo[0][a]=a&foo[0][b]=b&foo[1][a]=aa&foo[1][b]=bb"),{foo:[{a:"a",b:"b"},{a:"aa",b:"bb"}]}),e.deepEqual(qs.parse("a[]=b&a[t]=u&a[hasOwnProperty]=c",{allowPrototypes:!1}),{a:{0:"b",t:"u"}}),e.deepEqual(qs.parse("a[]=b&a[t]=u&a[hasOwnProperty]=c",{allowPrototypes:!0}),{a:{0:"b",t:"u",hasOwnProperty:"c"}}),e.deepEqual(qs.parse("a[]=b&a[hasOwnProperty]=c&a[x]=y",{allowPrototypes:!1}),{a:{0:"b",x:"y"}}),e.deepEqual(qs.parse("a[]=b&a[hasOwnProperty]=c&a[x]=y",{allowPrototypes:!0}),{a:{0:"b",hasOwnProperty:"c",x:"y"}}),e.end()})),e.test("transforms arrays to objects (dot notation)",(function(e){e.deepEqual(qs.parse("foo[0].baz=bar&fool.bad=baz",{allowDots:!0}),{foo:[{baz:"bar"}],fool:{bad:"baz"}}),e.deepEqual(qs.parse("foo[0].baz=bar&fool.bad.boo=baz",{allowDots:!0}),{foo:[{baz:"bar"}],fool:{bad:{boo:"baz"}}}),e.deepEqual(qs.parse("foo[0][0].baz=bar&fool.bad=baz",{allowDots:!0}),{foo:[[{baz:"bar"}]],fool:{bad:"baz"}}),e.deepEqual(qs.parse("foo[0].baz[0]=15&foo[0].bar=2",{allowDots:!0}),{foo:[{baz:["15"],bar:"2"}]}),e.deepEqual(qs.parse("foo[0].baz[0]=15&foo[0].baz[1]=16&foo[0].bar=2",{allowDots:!0}),{foo:[{baz:["15","16"],bar:"2"}]}),e.deepEqual(qs.parse("foo.bad=baz&foo[0]=bar",{allowDots:!0}),{foo:{bad:"baz",0:"bar"}}),e.deepEqual(qs.parse("foo.bad=baz&foo[]=bar",{allowDots:!0}),{foo:{bad:"baz",0:"bar"}}),e.deepEqual(qs.parse("foo[]=bar&foo.bad=baz",{allowDots:!0}),{foo:{0:"bar",bad:"baz"}}),e.deepEqual(qs.parse("foo.bad=baz&foo[]=bar&foo[]=foo",{allowDots:!0}),{foo:{bad:"baz",0:"bar",1:"foo"}}),e.deepEqual(qs.parse("foo[0].a=a&foo[0].b=b&foo[1].a=aa&foo[1].b=bb",{allowDots:!0}),{foo:[{a:"a",b:"b"},{a:"aa",b:"bb"}]}),e.end()})),e.test("correctly prunes undefined values when converting an array to an object",(function(e){e.deepEqual(qs.parse("a[2]=b&a[99999999]=c"),{a:{2:"b",99999999:"c"}}),e.end()})),e.test("supports malformed uri characters",(function(e){e.deepEqual(qs.parse("{%:%}",{strictNullHandling:!0}),{"{%:%}":null}),e.deepEqual(qs.parse("{%:%}="),{"{%:%}":""}),e.deepEqual(qs.parse("foo=%:%}"),{foo:"%:%}"}),e.end()})),e.test("doesn't produce empty keys",(function(e){e.deepEqual(qs.parse("_r=1&"),{_r:"1"}),e.end()})),e.test("cannot access Object prototype",(function(e){qs.parse("constructor[prototype][bad]=bad"),qs.parse("bad[constructor][prototype][bad]=bad"),e.equal(typeof Object.prototype.bad,"undefined"),e.end()})),e.test("parses arrays of objects",(function(e){e.deepEqual(qs.parse("a[][b]=c"),{a:[{b:"c"}]}),e.deepEqual(qs.parse("a[0][b]=c"),{a:[{b:"c"}]}),e.end()})),e.test("allows for empty strings in arrays",(function(e){e.deepEqual(qs.parse("a[]=b&a[]=&a[]=c"),{a:["b","","c"]}),e.deepEqual(qs.parse("a[0]=b&a[1]&a[2]=c&a[19]=",{strictNullHandling:!0,arrayLimit:20}),{a:["b",null,"c",""]},"with arrayLimit 20 + array indices: null then empty string works"),e.deepEqual(qs.parse("a[]=b&a[]&a[]=c&a[]=",{strictNullHandling:!0,arrayLimit:0}),{a:["b",null,"c",""]},"with arrayLimit 0 + array brackets: null then empty string works"),e.deepEqual(qs.parse("a[0]=b&a[1]=&a[2]=c&a[19]",{strictNullHandling:!0,arrayLimit:20}),{a:["b","","c",null]},"with arrayLimit 20 + array indices: empty string then null works"),e.deepEqual(qs.parse("a[]=b&a[]=&a[]=c&a[]",{strictNullHandling:!0,arrayLimit:0}),{a:["b","","c",null]},"with arrayLimit 0 + array brackets: empty string then null works"),e.deepEqual(qs.parse("a[]=&a[]=b&a[]=c"),{a:["","b","c"]},"array brackets: empty strings work"),e.end()})),e.test("compacts sparse arrays",(function(e){e.deepEqual(qs.parse("a[10]=1&a[2]=2",{arrayLimit:20}),{a:["2","1"]}),e.deepEqual(qs.parse("a[1][b][2][c]=1",{arrayLimit:20}),{a:[{b:[{c:"1"}]}]}),e.deepEqual(qs.parse("a[1][2][3][c]=1",{arrayLimit:20}),{a:[[[{c:"1"}]]]}),e.deepEqual(qs.parse("a[1][2][3][c][1]=1",{arrayLimit:20}),{a:[[[{c:["1"]}]]]}),e.end()})),e.test("parses semi-parsed strings",(function(e){e.deepEqual(qs.parse({"a[b]":"c"}),{a:{b:"c"}}),e.deepEqual(qs.parse({"a[b]":"c","a[d]":"e"}),{a:{b:"c",d:"e"}}),e.end()})),e.test("parses buffers correctly",(function(e){var a=SaferBuffer.from("test");e.deepEqual(qs.parse({a:a}),{a:a}),e.end()})),e.test("parses jquery-param strings",(function(e){e.deepEqual(qs.parse("filter%5B0%5D%5B%5D=int1&filter%5B0%5D%5B%5D=%3D&filter%5B0%5D%5B%5D=77&filter%5B%5D=and&filter%5B2%5D%5B%5D=int2&filter%5B2%5D%5B%5D=%3D&filter%5B2%5D%5B%5D=8"),{filter:[["int1","=","77"],"and",["int2","=","8"]]}),e.end()})),e.test("continues parsing when no parent is found",(function(e){e.deepEqual(qs.parse("[]=&a=b"),{0:"",a:"b"}),e.deepEqual(qs.parse("[]&a=b",{strictNullHandling:!0}),{0:null,a:"b"}),e.deepEqual(qs.parse("[foo]=bar"),{foo:"bar"}),e.end()})),e.test("does not error when parsing a very long array",(function(e){for(var a="a[]=a";Buffer.byteLength(a)<131072;)a=a+"&"+a;e.doesNotThrow((function(){qs.parse(a)})),e.end()})),e.test("should not throw when a native prototype has an enumerable property",(function(e){Object.prototype.crash="",Array.prototype.crash="",e.doesNotThrow(qs.parse.bind(null,"a=b")),e.deepEqual(qs.parse("a=b"),{a:"b"}),e.doesNotThrow(qs.parse.bind(null,"a[][b]=c")),e.deepEqual(qs.parse("a[][b]=c"),{a:[{b:"c"}]}),delete Object.prototype.crash,delete Array.prototype.crash,e.end()})),e.test("parses a string with an alternative string delimiter",(function(e){e.deepEqual(qs.parse("a=b;c=d",{delimiter:";"}),{a:"b",c:"d"}),e.end()})),e.test("parses a string with an alternative RegExp delimiter",(function(e){e.deepEqual(qs.parse("a=b; c=d",{delimiter:/[;,] */}),{a:"b",c:"d"}),e.end()})),e.test("does not use non-splittable objects as delimiters",(function(e){e.deepEqual(qs.parse("a=b&c=d",{delimiter:!0}),{a:"b",c:"d"}),e.end()})),e.test("allows overriding parameter limit",(function(e){e.deepEqual(qs.parse("a=b&c=d",{parameterLimit:1}),{a:"b"}),e.end()})),e.test("allows setting the parameter limit to Infinity",(function(e){e.deepEqual(qs.parse("a=b&c=d",{parameterLimit:1/0}),{a:"b",c:"d"}),e.end()})),e.test("allows overriding array limit",(function(e){e.deepEqual(qs.parse("a[0]=b",{arrayLimit:-1}),{a:{0:"b"}}),e.deepEqual(qs.parse("a[-1]=b",{arrayLimit:-1}),{a:{"-1":"b"}}),e.deepEqual(qs.parse("a[0]=b&a[1]=c",{arrayLimit:0}),{a:{0:"b",1:"c"}}),e.end()})),e.test("allows disabling array parsing",(function(e){var a=qs.parse("a[0]=b&a[1]=c",{parseArrays:!1});e.deepEqual(a,{a:{0:"b",1:"c"}}),e.equal(Array.isArray(a.a),!1,"parseArrays:false, indices case is not an array");var s=qs.parse("a[]=b",{parseArrays:!1});e.deepEqual(s,{a:{0:"b"}}),e.equal(Array.isArray(s.a),!1,"parseArrays:false, empty brackets case is not an array"),e.end()})),e.test("allows for query string prefix",(function(e){e.deepEqual(qs.parse("?foo=bar",{ignoreQueryPrefix:!0}),{foo:"bar"}),e.deepEqual(qs.parse("foo=bar",{ignoreQueryPrefix:!0}),{foo:"bar"}),e.deepEqual(qs.parse("?foo=bar",{ignoreQueryPrefix:!1}),{"?foo":"bar"}),e.end()})),e.test("parses an object",(function(e){var a=qs.parse({"user[name]":{"pop[bob]":3},"user[email]":null});e.deepEqual(a,{user:{name:{"pop[bob]":3},email:null}}),e.end()})),e.test("parses string with comma as array divider",(function(e){e.deepEqual(qs.parse("foo=bar,tee",{comma:!0}),{foo:["bar","tee"]}),e.deepEqual(qs.parse("foo[bar]=coffee,tee",{comma:!0}),{foo:{bar:["coffee","tee"]}}),e.deepEqual(qs.parse("foo=",{comma:!0}),{foo:""}),e.deepEqual(qs.parse("foo",{comma:!0}),{foo:""}),e.deepEqual(qs.parse("foo",{comma:!0,strictNullHandling:!0}),{foo:null}),e.end()})),e.test("parses an object in dot notation",(function(e){var a=qs.parse({"user.name":{"pop[bob]":3},"user.email.":null},{allowDots:!0});e.deepEqual(a,{user:{name:{"pop[bob]":3},email:null}}),e.end()})),e.test("parses an object and not child values",(function(e){var a=qs.parse({"user[name]":{"pop[bob]":{test:3}},"user[email]":null});e.deepEqual(a,{user:{name:{"pop[bob]":{test:3}},email:null}}),e.end()})),e.test("does not blow up when Buffer global is missing",(function(e){var a=global.Buffer;delete global.Buffer;var s=qs.parse("a=b&c=d");global.Buffer=a,e.deepEqual(s,{a:"b",c:"d"}),e.end()})),e.test("does not crash when parsing circular references",(function(e){var a,s={};s.b=s,e.doesNotThrow((function(){a=qs.parse({"foo[bar]":"baz","foo[baz]":s})})),e.equal("foo"in a,!0,'parsed has "foo" property'),e.equal("bar"in a.foo,!0),e.equal("baz"in a.foo,!0),e.equal(a.foo.bar,"baz"),e.deepEqual(a.foo.baz,s),e.end()})),e.test("does not crash when parsing deep objects",(function(e){for(var a,s="foo",r=0;r<5e3;r++)s+="[p]";s+="=bar",e.doesNotThrow((function(){a=qs.parse(s,{depth:5e3})})),e.equal("foo"in a,!0,'parsed has "foo" property');for(var t=0,o=a.foo;o=o.p;)t+=1;e.equal(t,5e3,"parsed is 5000 properties deep"),e.end()})),e.test("parses null objects correctly",{skip:!Object.create},(function(e){var a=Object.create(null);a.b="c",e.deepEqual(qs.parse(a),{b:"c"});var s=qs.parse({a:a});e.equal("a"in s,!0,'result has "a" property'),e.deepEqual(s.a,a),e.end()})),e.test("parses dates correctly",(function(e){var a=new Date;e.deepEqual(qs.parse({a:a}),{a:a}),e.end()})),e.test("parses regular expressions correctly",(function(e){var a=/^test$/;e.deepEqual(qs.parse({a:a}),{a:a}),e.end()})),e.test("does not allow overwriting prototype properties",(function(e){e.deepEqual(qs.parse("a[hasOwnProperty]=b",{allowPrototypes:!1}),{}),e.deepEqual(qs.parse("hasOwnProperty=b",{allowPrototypes:!1}),{}),e.deepEqual(qs.parse("toString",{allowPrototypes:!1}),{},'bare "toString" results in {}'),e.end()})),e.test("can allow overwriting prototype properties",(function(e){e.deepEqual(qs.parse("a[hasOwnProperty]=b",{allowPrototypes:!0}),{a:{hasOwnProperty:"b"}}),e.deepEqual(qs.parse("hasOwnProperty=b",{allowPrototypes:!0}),{hasOwnProperty:"b"}),e.deepEqual(qs.parse("toString",{allowPrototypes:!0}),{toString:""},'bare "toString" results in { toString: "" }'),e.end()})),e.test("params starting with a closing bracket",(function(e){e.deepEqual(qs.parse("]=toString"),{"]":"toString"}),e.deepEqual(qs.parse("]]=toString"),{"]]":"toString"}),e.deepEqual(qs.parse("]hello]=toString"),{"]hello]":"toString"}),e.end()})),e.test("params starting with a starting bracket",(function(e){e.deepEqual(qs.parse("[=toString"),{"[":"toString"}),e.deepEqual(qs.parse("[[=toString"),{"[[":"toString"}),e.deepEqual(qs.parse("[hello[=toString"),{"[hello[":"toString"}),e.end()})),e.test("add keys to objects",(function(e){e.deepEqual(qs.parse("a[b]=c&a=d"),{a:{b:"c",d:!0}},"can add keys to objects"),e.deepEqual(qs.parse("a[b]=c&a=toString"),{a:{b:"c"}},"can not overwrite prototype"),e.deepEqual(qs.parse("a[b]=c&a=toString",{allowPrototypes:!0}),{a:{b:"c",toString:!0}},"can overwrite prototype with allowPrototypes true"),e.deepEqual(qs.parse("a[b]=c&a=toString",{plainObjects:!0}),{a:{b:"c",toString:!0}},"can overwrite prototype with plainObjects true"),e.end()})),e.test("can return null objects",{skip:!Object.create},(function(e){var a=Object.create(null);a.a=Object.create(null),a.a.b="c",a.a.hasOwnProperty="d",e.deepEqual(qs.parse("a[b]=c&a[hasOwnProperty]=d",{plainObjects:!0}),a),e.deepEqual(qs.parse(null,{plainObjects:!0}),Object.create(null));var s=Object.create(null);s.a=Object.create(null),s.a[0]="b",s.a.c="d",e.deepEqual(qs.parse("a[]=b&a[c]=d",{plainObjects:!0}),s),e.end()})),e.test("can parse with custom encoding",(function(e){e.deepEqual(qs.parse("%8c%a7=%91%e5%8d%e3%95%7b",{decoder:function(e){for(var a=/%([0-9A-F]{2})/gi,s=[],r=a.exec(e);r;)s.push(parseInt(r[1],16)),r=a.exec(e);return String(iconv.decode(SaferBuffer.from(s),"shift_jis"))}}),{"県":"大阪府"}),e.end()})),e.test("receives the default decoder as a second argument",(function(e){e.plan(1),qs.parse("a",{decoder:function(a,s){e.equal(s,utils.decode)}}),e.end()})),e.test("throws error with wrong decoder",(function(e){e.throws((function(){qs.parse({},{decoder:"string"})}),new TypeError("Decoder has to be a function.")),e.end()})),e.test("does not mutate the options argument",(function(e){var a={};qs.parse("a[b]=true",a),e.deepEqual(a,{}),e.end()})),e.test("throws if an invalid charset is specified",(function(e){e.throws((function(){qs.parse("a=b",{charset:"foobar"})}),new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined")),e.end()})),e.test("parses an iso-8859-1 string if asked to",(function(e){e.deepEqual(qs.parse("%A2=%BD",{charset:"iso-8859-1"}),{"¢":"½"}),e.end()}));e.test("prefers an utf-8 charset specified by the utf8 sentinel to a default charset of iso-8859-1",(function(e){e.deepEqual(qs.parse("utf8=%E2%9C%93&%C3%B8=%C3%B8",{charsetSentinel:!0,charset:"iso-8859-1"}),{"ø":"ø"}),e.end()})),e.test("prefers an iso-8859-1 charset specified by the utf8 sentinel to a default charset of utf-8",(function(e){e.deepEqual(qs.parse("utf8=%26%2310003%3B&%C3%B8=%C3%B8",{charsetSentinel:!0,charset:"utf-8"}),{"ø":"ø"}),e.end()})),e.test("does not require the utf8 sentinel to be defined before the parameters whose decoding it affects",(function(e){e.deepEqual(qs.parse("a=%C3%B8&utf8=%26%2310003%3B",{charsetSentinel:!0,charset:"utf-8"}),{a:"ø"}),e.end()})),e.test("should ignore an utf8 sentinel with an unknown value",(function(e){e.deepEqual(qs.parse("utf8=foo&%C3%B8=%C3%B8",{charsetSentinel:!0,charset:"utf-8"}),{"ø":"ø"}),e.end()})),e.test("uses the utf8 sentinel to switch to utf-8 when no default charset is given",(function(e){e.deepEqual(qs.parse("utf8=%E2%9C%93&%C3%B8=%C3%B8",{charsetSentinel:!0}),{"ø":"ø"}),e.end()})),e.test("uses the utf8 sentinel to switch to iso-8859-1 when no default charset is given",(function(e){e.deepEqual(qs.parse("utf8=%26%2310003%3B&%C3%B8=%C3%B8",{charsetSentinel:!0}),{"ø":"ø"}),e.end()})),e.test("interprets numeric entities in iso-8859-1 when `interpretNumericEntities`",(function(e){e.deepEqual(qs.parse("foo=%26%239786%3B",{charset:"iso-8859-1",interpretNumericEntities:!0}),{foo:"☺"}),e.end()})),e.test("handles a custom decoder returning `null`, in the `iso-8859-1` charset, when `interpretNumericEntities`",(function(e){e.deepEqual(qs.parse("foo=&bar=%26%239786%3B",{charset:"iso-8859-1",decoder:function(e,a,s){return e?a(e,a,s):null},interpretNumericEntities:!0}),{foo:null,bar:"☺"}),e.end()})),e.test("does not interpret numeric entities in iso-8859-1 when `interpretNumericEntities` is absent",(function(e){e.deepEqual(qs.parse("foo=%26%239786%3B",{charset:"iso-8859-1"}),{foo:"&#9786;"}),e.end()})),e.test("does not interpret numeric entities when the charset is utf-8, even when `interpretNumericEntities`",(function(e){e.deepEqual(qs.parse("foo=%26%239786%3B",{charset:"utf-8",interpretNumericEntities:!0}),{foo:"&#9786;"}),e.end()})),e.test("does not interpret %uXXXX syntax in iso-8859-1 mode",(function(e){e.deepEqual(qs.parse("%u263A=%u263A",{charset:"iso-8859-1"}),{"%u263A":"%u263A"}),e.end()})),e.end()}));