stringify.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  1. 'use strict';
  2. var test = require('tape');
  3. var qs = require('../');
  4. var utils = require('../lib/utils');
  5. var iconv = require('iconv-lite');
  6. var SaferBuffer = require('safer-buffer').Buffer;
  7. var hasSymbols = require('has-symbols');
  8. var hasBigInt = typeof BigInt === 'function';
  9. test('stringify()', function (t) {
  10. t.test('stringifies a querystring object', function (st) {
  11. st.equal(qs.stringify({ a: 'b' }), 'a=b');
  12. st.equal(qs.stringify({ a: 1 }), 'a=1');
  13. st.equal(qs.stringify({ a: 1, b: 2 }), 'a=1&b=2');
  14. st.equal(qs.stringify({ a: 'A_Z' }), 'a=A_Z');
  15. st.equal(qs.stringify({ a: '€' }), 'a=%E2%82%AC');
  16. st.equal(qs.stringify({ a: '' }), 'a=%EE%80%80');
  17. st.equal(qs.stringify({ a: 'א' }), 'a=%D7%90');
  18. st.equal(qs.stringify({ a: '𐐷' }), 'a=%F0%90%90%B7');
  19. st.end();
  20. });
  21. t.test('stringifies falsy values', function (st) {
  22. st.equal(qs.stringify(undefined), '');
  23. st.equal(qs.stringify(null), '');
  24. st.equal(qs.stringify(null, { strictNullHandling: true }), '');
  25. st.equal(qs.stringify(false), '');
  26. st.equal(qs.stringify(0), '');
  27. st.end();
  28. });
  29. t.test('stringifies symbols', { skip: !hasSymbols() }, function (st) {
  30. st.equal(qs.stringify(Symbol.iterator), '');
  31. st.equal(qs.stringify([Symbol.iterator]), '0=Symbol%28Symbol.iterator%29');
  32. st.equal(qs.stringify({ a: Symbol.iterator }), 'a=Symbol%28Symbol.iterator%29');
  33. st.equal(
  34. qs.stringify({ a: [Symbol.iterator] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),
  35. 'a[]=Symbol%28Symbol.iterator%29'
  36. );
  37. st.end();
  38. });
  39. t.test('stringifies bigints', { skip: !hasBigInt }, function (st) {
  40. var three = BigInt(3);
  41. var encodeWithN = function (value, defaultEncoder, charset) {
  42. var result = defaultEncoder(value, defaultEncoder, charset);
  43. return typeof value === 'bigint' ? result + 'n' : result;
  44. };
  45. st.equal(qs.stringify(three), '');
  46. st.equal(qs.stringify([three]), '0=3');
  47. st.equal(qs.stringify([three], { encoder: encodeWithN }), '0=3n');
  48. st.equal(qs.stringify({ a: three }), 'a=3');
  49. st.equal(qs.stringify({ a: three }, { encoder: encodeWithN }), 'a=3n');
  50. st.equal(
  51. qs.stringify({ a: [three] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),
  52. 'a[]=3'
  53. );
  54. st.equal(
  55. qs.stringify({ a: [three] }, { encodeValuesOnly: true, encoder: encodeWithN, arrayFormat: 'brackets' }),
  56. 'a[]=3n'
  57. );
  58. st.end();
  59. });
  60. t.test('adds query prefix', function (st) {
  61. st.equal(qs.stringify({ a: 'b' }, { addQueryPrefix: true }), '?a=b');
  62. st.end();
  63. });
  64. t.test('with query prefix, outputs blank string given an empty object', function (st) {
  65. st.equal(qs.stringify({}, { addQueryPrefix: true }), '');
  66. st.end();
  67. });
  68. t.test('stringifies nested falsy values', function (st) {
  69. st.equal(qs.stringify({ a: { b: { c: null } } }), 'a%5Bb%5D%5Bc%5D=');
  70. st.equal(qs.stringify({ a: { b: { c: null } } }, { strictNullHandling: true }), 'a%5Bb%5D%5Bc%5D');
  71. st.equal(qs.stringify({ a: { b: { c: false } } }), 'a%5Bb%5D%5Bc%5D=false');
  72. st.end();
  73. });
  74. t.test('stringifies a nested object', function (st) {
  75. st.equal(qs.stringify({ a: { b: 'c' } }), 'a%5Bb%5D=c');
  76. st.equal(qs.stringify({ a: { b: { c: { d: 'e' } } } }), 'a%5Bb%5D%5Bc%5D%5Bd%5D=e');
  77. st.end();
  78. });
  79. t.test('stringifies a nested object with dots notation', function (st) {
  80. st.equal(qs.stringify({ a: { b: 'c' } }, { allowDots: true }), 'a.b=c');
  81. st.equal(qs.stringify({ a: { b: { c: { d: 'e' } } } }, { allowDots: true }), 'a.b.c.d=e');
  82. st.end();
  83. });
  84. t.test('stringifies an array value', function (st) {
  85. st.equal(
  86. qs.stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'indices' }),
  87. 'a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d',
  88. 'indices => indices'
  89. );
  90. st.equal(
  91. qs.stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'brackets' }),
  92. 'a%5B%5D=b&a%5B%5D=c&a%5B%5D=d',
  93. 'brackets => brackets'
  94. );
  95. st.equal(
  96. qs.stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'comma' }),
  97. 'a=b%2Cc%2Cd',
  98. 'comma => comma'
  99. );
  100. st.equal(
  101. qs.stringify({ a: ['b', 'c', 'd'] }),
  102. 'a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d',
  103. 'default => indices'
  104. );
  105. st.end();
  106. });
  107. t.test('omits nulls when asked', function (st) {
  108. st.equal(qs.stringify({ a: 'b', c: null }, { skipNulls: true }), 'a=b');
  109. st.end();
  110. });
  111. t.test('omits nested nulls when asked', function (st) {
  112. st.equal(qs.stringify({ a: { b: 'c', d: null } }, { skipNulls: true }), 'a%5Bb%5D=c');
  113. st.end();
  114. });
  115. t.test('omits array indices when asked', function (st) {
  116. st.equal(qs.stringify({ a: ['b', 'c', 'd'] }, { indices: false }), 'a=b&a=c&a=d');
  117. st.end();
  118. });
  119. t.test('stringifies an array value with one item vs multiple items', function (st) {
  120. st.test('non-array item', function (s2t) {
  121. s2t.equal(qs.stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a=c');
  122. s2t.equal(qs.stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a=c');
  123. s2t.equal(qs.stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=c');
  124. s2t.equal(qs.stringify({ a: 'c' }, { encodeValuesOnly: true }), 'a=c');
  125. s2t.end();
  126. });
  127. st.test('array with a single item', function (s2t) {
  128. s2t.equal(qs.stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[0]=c');
  129. s2t.equal(qs.stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[]=c');
  130. s2t.equal(qs.stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=c');
  131. s2t.equal(qs.stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'comma', commaRoundTrip: true }), 'a[]=c'); // so it parses back as an array
  132. s2t.equal(qs.stringify({ a: ['c'] }, { encodeValuesOnly: true }), 'a[0]=c');
  133. s2t.end();
  134. });
  135. st.test('array with multiple items', function (s2t) {
  136. s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[0]=c&a[1]=d');
  137. s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[]=c&a[]=d');
  138. s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=c,d');
  139. s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true }), 'a[0]=c&a[1]=d');
  140. s2t.end();
  141. });
  142. st.test('array with multiple items with a comma inside', function (s2t) {
  143. s2t.equal(qs.stringify({ a: ['c,d', 'e'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=c%2Cd,e');
  144. s2t.equal(qs.stringify({ a: ['c,d', 'e'] }, { arrayFormat: 'comma' }), 'a=c%2Cd%2Ce');
  145. s2t.end();
  146. });
  147. st.end();
  148. });
  149. t.test('stringifies a nested array value', function (st) {
  150. st.equal(qs.stringify({ a: { b: ['c', 'd'] } }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[b][0]=c&a[b][1]=d');
  151. st.equal(qs.stringify({ a: { b: ['c', 'd'] } }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[b][]=c&a[b][]=d');
  152. st.equal(qs.stringify({ a: { b: ['c', 'd'] } }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a[b]=c,d');
  153. st.equal(qs.stringify({ a: { b: ['c', 'd'] } }, { encodeValuesOnly: true }), 'a[b][0]=c&a[b][1]=d');
  154. st.end();
  155. });
  156. t.test('stringifies comma and empty array values', function (st) {
  157. st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'indices' }), 'a[0]=,&a[1]=&a[2]=c,d%');
  158. st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'brackets' }), 'a[]=,&a[]=&a[]=c,d%');
  159. st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'comma' }), 'a=,,,c,d%');
  160. st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'repeat' }), 'a=,&a=&a=c,d%');
  161. st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[0]=%2C&a[1]=&a[2]=c%2Cd%25');
  162. st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[]=%2C&a[]=&a[]=c%2Cd%25');
  163. st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=%2C,,c%2Cd%25');
  164. st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: true, arrayFormat: 'repeat' }), 'a=%2C&a=&a=c%2Cd%25');
  165. st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'indices' }), 'a%5B0%5D=%2C&a%5B1%5D=&a%5B2%5D=c%2Cd%25');
  166. st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'brackets' }), 'a%5B%5D=%2C&a%5B%5D=&a%5B%5D=c%2Cd%25');
  167. st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'comma' }), 'a=%2C%2C%2Cc%2Cd%25');
  168. st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'repeat' }), 'a=%2C&a=&a=c%2Cd%25');
  169. st.end();
  170. });
  171. t.test('stringifies comma and empty non-array values', function (st) {
  172. st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'indices' }), 'a=,&b=&c=c,d%');
  173. st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'brackets' }), 'a=,&b=&c=c,d%');
  174. st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'comma' }), 'a=,&b=&c=c,d%');
  175. st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'repeat' }), 'a=,&b=&c=c,d%');
  176. st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: true, arrayFormat: 'indices' }), 'a=%2C&b=&c=c%2Cd%25');
  177. st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a=%2C&b=&c=c%2Cd%25');
  178. st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=%2C&b=&c=c%2Cd%25');
  179. st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: true, arrayFormat: 'repeat' }), 'a=%2C&b=&c=c%2Cd%25');
  180. st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: false, arrayFormat: 'indices' }), 'a=%2C&b=&c=c%2Cd%25');
  181. st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: false, arrayFormat: 'brackets' }), 'a=%2C&b=&c=c%2Cd%25');
  182. st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: false, arrayFormat: 'comma' }), 'a=%2C&b=&c=c%2Cd%25');
  183. st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: false, arrayFormat: 'repeat' }), 'a=%2C&b=&c=c%2Cd%25');
  184. st.end();
  185. });
  186. t.test('stringifies a nested array value with dots notation', function (st) {
  187. st.equal(
  188. qs.stringify(
  189. { a: { b: ['c', 'd'] } },
  190. { allowDots: true, encodeValuesOnly: true, arrayFormat: 'indices' }
  191. ),
  192. 'a.b[0]=c&a.b[1]=d',
  193. 'indices: stringifies with dots + indices'
  194. );
  195. st.equal(
  196. qs.stringify(
  197. { a: { b: ['c', 'd'] } },
  198. { allowDots: true, encodeValuesOnly: true, arrayFormat: 'brackets' }
  199. ),
  200. 'a.b[]=c&a.b[]=d',
  201. 'brackets: stringifies with dots + brackets'
  202. );
  203. st.equal(
  204. qs.stringify(
  205. { a: { b: ['c', 'd'] } },
  206. { allowDots: true, encodeValuesOnly: true, arrayFormat: 'comma' }
  207. ),
  208. 'a.b=c,d',
  209. 'comma: stringifies with dots + comma'
  210. );
  211. st.equal(
  212. qs.stringify(
  213. { a: { b: ['c', 'd'] } },
  214. { allowDots: true, encodeValuesOnly: true }
  215. ),
  216. 'a.b[0]=c&a.b[1]=d',
  217. 'default: stringifies with dots + indices'
  218. );
  219. st.end();
  220. });
  221. t.test('stringifies an object inside an array', function (st) {
  222. st.equal(
  223. qs.stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'indices' }),
  224. 'a%5B0%5D%5Bb%5D=c', // a[0][b]=c
  225. 'indices => brackets'
  226. );
  227. st.equal(
  228. qs.stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'brackets' }),
  229. 'a%5B%5D%5Bb%5D=c', // a[][b]=c
  230. 'brackets => brackets'
  231. );
  232. st.equal(
  233. qs.stringify({ a: [{ b: 'c' }] }),
  234. 'a%5B0%5D%5Bb%5D=c',
  235. 'default => indices'
  236. );
  237. st.equal(
  238. qs.stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'indices' }),
  239. 'a%5B0%5D%5Bb%5D%5Bc%5D%5B0%5D=1',
  240. 'indices => indices'
  241. );
  242. st.equal(
  243. qs.stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'brackets' }),
  244. 'a%5B%5D%5Bb%5D%5Bc%5D%5B%5D=1',
  245. 'brackets => brackets'
  246. );
  247. st.equal(
  248. qs.stringify({ a: [{ b: { c: [1] } }] }),
  249. 'a%5B0%5D%5Bb%5D%5Bc%5D%5B0%5D=1',
  250. 'default => indices'
  251. );
  252. st.end();
  253. });
  254. t.test('stringifies an array with mixed objects and primitives', function (st) {
  255. st.equal(
  256. qs.stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true, arrayFormat: 'indices' }),
  257. 'a[0][b]=1&a[1]=2&a[2]=3',
  258. 'indices => indices'
  259. );
  260. st.equal(
  261. qs.stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),
  262. 'a[][b]=1&a[]=2&a[]=3',
  263. 'brackets => brackets'
  264. );
  265. st.equal(
  266. qs.stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true, arrayFormat: 'comma' }),
  267. '???',
  268. 'brackets => brackets',
  269. { skip: 'TODO: figure out what this should do' }
  270. );
  271. st.equal(
  272. qs.stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true }),
  273. 'a[0][b]=1&a[1]=2&a[2]=3',
  274. 'default => indices'
  275. );
  276. st.end();
  277. });
  278. t.test('stringifies an object inside an array with dots notation', function (st) {
  279. st.equal(
  280. qs.stringify(
  281. { a: [{ b: 'c' }] },
  282. { allowDots: true, encode: false, arrayFormat: 'indices' }
  283. ),
  284. 'a[0].b=c',
  285. 'indices => indices'
  286. );
  287. st.equal(
  288. qs.stringify(
  289. { a: [{ b: 'c' }] },
  290. { allowDots: true, encode: false, arrayFormat: 'brackets' }
  291. ),
  292. 'a[].b=c',
  293. 'brackets => brackets'
  294. );
  295. st.equal(
  296. qs.stringify(
  297. { a: [{ b: 'c' }] },
  298. { allowDots: true, encode: false }
  299. ),
  300. 'a[0].b=c',
  301. 'default => indices'
  302. );
  303. st.equal(
  304. qs.stringify(
  305. { a: [{ b: { c: [1] } }] },
  306. { allowDots: true, encode: false, arrayFormat: 'indices' }
  307. ),
  308. 'a[0].b.c[0]=1',
  309. 'indices => indices'
  310. );
  311. st.equal(
  312. qs.stringify(
  313. { a: [{ b: { c: [1] } }] },
  314. { allowDots: true, encode: false, arrayFormat: 'brackets' }
  315. ),
  316. 'a[].b.c[]=1',
  317. 'brackets => brackets'
  318. );
  319. st.equal(
  320. qs.stringify(
  321. { a: [{ b: { c: [1] } }] },
  322. { allowDots: true, encode: false }
  323. ),
  324. 'a[0].b.c[0]=1',
  325. 'default => indices'
  326. );
  327. st.end();
  328. });
  329. t.test('does not omit object keys when indices = false', function (st) {
  330. st.equal(qs.stringify({ a: [{ b: 'c' }] }, { indices: false }), 'a%5Bb%5D=c');
  331. st.end();
  332. });
  333. t.test('uses indices notation for arrays when indices=true', function (st) {
  334. st.equal(qs.stringify({ a: ['b', 'c'] }, { indices: true }), 'a%5B0%5D=b&a%5B1%5D=c');
  335. st.end();
  336. });
  337. t.test('uses indices notation for arrays when no arrayFormat is specified', function (st) {
  338. st.equal(qs.stringify({ a: ['b', 'c'] }), 'a%5B0%5D=b&a%5B1%5D=c');
  339. st.end();
  340. });
  341. t.test('uses indices notation for arrays when no arrayFormat=indices', function (st) {
  342. st.equal(qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' }), 'a%5B0%5D=b&a%5B1%5D=c');
  343. st.end();
  344. });
  345. t.test('uses repeat notation for arrays when no arrayFormat=repeat', function (st) {
  346. st.equal(qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' }), 'a=b&a=c');
  347. st.end();
  348. });
  349. t.test('uses brackets notation for arrays when no arrayFormat=brackets', function (st) {
  350. st.equal(qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' }), 'a%5B%5D=b&a%5B%5D=c');
  351. st.end();
  352. });
  353. t.test('stringifies a complicated object', function (st) {
  354. st.equal(qs.stringify({ a: { b: 'c', d: 'e' } }), 'a%5Bb%5D=c&a%5Bd%5D=e');
  355. st.end();
  356. });
  357. t.test('stringifies an empty value', function (st) {
  358. st.equal(qs.stringify({ a: '' }), 'a=');
  359. st.equal(qs.stringify({ a: null }, { strictNullHandling: true }), 'a');
  360. st.equal(qs.stringify({ a: '', b: '' }), 'a=&b=');
  361. st.equal(qs.stringify({ a: null, b: '' }, { strictNullHandling: true }), 'a&b=');
  362. st.equal(qs.stringify({ a: { b: '' } }), 'a%5Bb%5D=');
  363. st.equal(qs.stringify({ a: { b: null } }, { strictNullHandling: true }), 'a%5Bb%5D');
  364. st.equal(qs.stringify({ a: { b: null } }, { strictNullHandling: false }), 'a%5Bb%5D=');
  365. st.end();
  366. });
  367. t.test('stringifies an empty array in different arrayFormat', function (st) {
  368. st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false }), 'b[0]=&c=c');
  369. // arrayFormat default
  370. st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'indices' }), 'b[0]=&c=c');
  371. st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'brackets' }), 'b[]=&c=c');
  372. st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'repeat' }), 'b=&c=c');
  373. st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma' }), 'b=&c=c');
  374. st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma', commaRoundTrip: true }), 'b[]=&c=c');
  375. // with strictNullHandling
  376. st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'indices', strictNullHandling: true }), 'b[0]&c=c');
  377. st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'brackets', strictNullHandling: true }), 'b[]&c=c');
  378. st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'repeat', strictNullHandling: true }), 'b&c=c');
  379. st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma', strictNullHandling: true }), 'b&c=c');
  380. st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma', strictNullHandling: true, commaRoundTrip: true }), 'b[]&c=c');
  381. // with skipNulls
  382. st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'indices', skipNulls: true }), 'c=c');
  383. st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'brackets', skipNulls: true }), 'c=c');
  384. st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'repeat', skipNulls: true }), 'c=c');
  385. st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma', skipNulls: true }), 'c=c');
  386. st.end();
  387. });
  388. t.test('stringifies a null object', { skip: !Object.create }, function (st) {
  389. var obj = Object.create(null);
  390. obj.a = 'b';
  391. st.equal(qs.stringify(obj), 'a=b');
  392. st.end();
  393. });
  394. t.test('returns an empty string for invalid input', function (st) {
  395. st.equal(qs.stringify(undefined), '');
  396. st.equal(qs.stringify(false), '');
  397. st.equal(qs.stringify(null), '');
  398. st.equal(qs.stringify(''), '');
  399. st.end();
  400. });
  401. t.test('stringifies an object with a null object as a child', { skip: !Object.create }, function (st) {
  402. var obj = { a: Object.create(null) };
  403. obj.a.b = 'c';
  404. st.equal(qs.stringify(obj), 'a%5Bb%5D=c');
  405. st.end();
  406. });
  407. t.test('drops keys with a value of undefined', function (st) {
  408. st.equal(qs.stringify({ a: undefined }), '');
  409. st.equal(qs.stringify({ a: { b: undefined, c: null } }, { strictNullHandling: true }), 'a%5Bc%5D');
  410. st.equal(qs.stringify({ a: { b: undefined, c: null } }, { strictNullHandling: false }), 'a%5Bc%5D=');
  411. st.equal(qs.stringify({ a: { b: undefined, c: '' } }), 'a%5Bc%5D=');
  412. st.end();
  413. });
  414. t.test('url encodes values', function (st) {
  415. st.equal(qs.stringify({ a: 'b c' }), 'a=b%20c');
  416. st.end();
  417. });
  418. t.test('stringifies a date', function (st) {
  419. var now = new Date();
  420. var str = 'a=' + encodeURIComponent(now.toISOString());
  421. st.equal(qs.stringify({ a: now }), str);
  422. st.end();
  423. });
  424. t.test('stringifies the weird object from qs', function (st) {
  425. st.equal(qs.stringify({ 'my weird field': '~q1!2"\'w$5&7/z8)?' }), 'my%20weird%20field=~q1%212%22%27w%245%267%2Fz8%29%3F');
  426. st.end();
  427. });
  428. t.test('skips properties that are part of the object prototype', function (st) {
  429. Object.prototype.crash = 'test';
  430. st.equal(qs.stringify({ a: 'b' }), 'a=b');
  431. st.equal(qs.stringify({ a: { b: 'c' } }), 'a%5Bb%5D=c');
  432. delete Object.prototype.crash;
  433. st.end();
  434. });
  435. t.test('stringifies boolean values', function (st) {
  436. st.equal(qs.stringify({ a: true }), 'a=true');
  437. st.equal(qs.stringify({ a: { b: true } }), 'a%5Bb%5D=true');
  438. st.equal(qs.stringify({ b: false }), 'b=false');
  439. st.equal(qs.stringify({ b: { c: false } }), 'b%5Bc%5D=false');
  440. st.end();
  441. });
  442. t.test('stringifies buffer values', function (st) {
  443. st.equal(qs.stringify({ a: SaferBuffer.from('test') }), 'a=test');
  444. st.equal(qs.stringify({ a: { b: SaferBuffer.from('test') } }), 'a%5Bb%5D=test');
  445. st.end();
  446. });
  447. t.test('stringifies an object using an alternative delimiter', function (st) {
  448. st.equal(qs.stringify({ a: 'b', c: 'd' }, { delimiter: ';' }), 'a=b;c=d');
  449. st.end();
  450. });
  451. t.test('does not blow up when Buffer global is missing', function (st) {
  452. var tempBuffer = global.Buffer;
  453. delete global.Buffer;
  454. var result = qs.stringify({ a: 'b', c: 'd' });
  455. global.Buffer = tempBuffer;
  456. st.equal(result, 'a=b&c=d');
  457. st.end();
  458. });
  459. t.test('does not crash when parsing circular references', function (st) {
  460. var a = {};
  461. a.b = a;
  462. st['throws'](
  463. function () { qs.stringify({ 'foo[bar]': 'baz', 'foo[baz]': a }); },
  464. /RangeError: Cyclic object value/,
  465. 'cyclic values throw'
  466. );
  467. var circular = {
  468. a: 'value'
  469. };
  470. circular.a = circular;
  471. st['throws'](
  472. function () { qs.stringify(circular); },
  473. /RangeError: Cyclic object value/,
  474. 'cyclic values throw'
  475. );
  476. var arr = ['a'];
  477. st.doesNotThrow(
  478. function () { qs.stringify({ x: arr, y: arr }); },
  479. 'non-cyclic values do not throw'
  480. );
  481. st.end();
  482. });
  483. t.test('non-circular duplicated references can still work', function (st) {
  484. var hourOfDay = {
  485. 'function': 'hour_of_day'
  486. };
  487. var p1 = {
  488. 'function': 'gte',
  489. arguments: [hourOfDay, 0]
  490. };
  491. var p2 = {
  492. 'function': 'lte',
  493. arguments: [hourOfDay, 23]
  494. };
  495. st.equal(
  496. qs.stringify({ filters: { $and: [p1, p2] } }, { encodeValuesOnly: true }),
  497. 'filters[$and][0][function]=gte&filters[$and][0][arguments][0][function]=hour_of_day&filters[$and][0][arguments][1]=0&filters[$and][1][function]=lte&filters[$and][1][arguments][0][function]=hour_of_day&filters[$and][1][arguments][1]=23'
  498. );
  499. st.end();
  500. });
  501. t.test('selects properties when filter=array', function (st) {
  502. st.equal(qs.stringify({ a: 'b' }, { filter: ['a'] }), 'a=b');
  503. st.equal(qs.stringify({ a: 1 }, { filter: [] }), '');
  504. st.equal(
  505. qs.stringify(
  506. { a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' },
  507. { filter: ['a', 'b', 0, 2], arrayFormat: 'indices' }
  508. ),
  509. 'a%5Bb%5D%5B0%5D=1&a%5Bb%5D%5B2%5D=3',
  510. 'indices => indices'
  511. );
  512. st.equal(
  513. qs.stringify(
  514. { a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' },
  515. { filter: ['a', 'b', 0, 2], arrayFormat: 'brackets' }
  516. ),
  517. 'a%5Bb%5D%5B%5D=1&a%5Bb%5D%5B%5D=3',
  518. 'brackets => brackets'
  519. );
  520. st.equal(
  521. qs.stringify(
  522. { a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' },
  523. { filter: ['a', 'b', 0, 2] }
  524. ),
  525. 'a%5Bb%5D%5B0%5D=1&a%5Bb%5D%5B2%5D=3',
  526. 'default => indices'
  527. );
  528. st.end();
  529. });
  530. t.test('supports custom representations when filter=function', function (st) {
  531. var calls = 0;
  532. var obj = { a: 'b', c: 'd', e: { f: new Date(1257894000000) } };
  533. var filterFunc = function (prefix, value) {
  534. calls += 1;
  535. if (calls === 1) {
  536. st.equal(prefix, '', 'prefix is empty');
  537. st.equal(value, obj);
  538. } else if (prefix === 'c') {
  539. return void 0;
  540. } else if (value instanceof Date) {
  541. st.equal(prefix, 'e[f]');
  542. return value.getTime();
  543. }
  544. return value;
  545. };
  546. st.equal(qs.stringify(obj, { filter: filterFunc }), 'a=b&e%5Bf%5D=1257894000000');
  547. st.equal(calls, 5);
  548. st.end();
  549. });
  550. t.test('can disable uri encoding', function (st) {
  551. st.equal(qs.stringify({ a: 'b' }, { encode: false }), 'a=b');
  552. st.equal(qs.stringify({ a: { b: 'c' } }, { encode: false }), 'a[b]=c');
  553. st.equal(qs.stringify({ a: 'b', c: null }, { strictNullHandling: true, encode: false }), 'a=b&c');
  554. st.end();
  555. });
  556. t.test('can sort the keys', function (st) {
  557. var sort = function (a, b) {
  558. return a.localeCompare(b);
  559. };
  560. st.equal(qs.stringify({ a: 'c', z: 'y', b: 'f' }, { sort: sort }), 'a=c&b=f&z=y');
  561. st.equal(qs.stringify({ a: 'c', z: { j: 'a', i: 'b' }, b: 'f' }, { sort: sort }), 'a=c&b=f&z%5Bi%5D=b&z%5Bj%5D=a');
  562. st.end();
  563. });
  564. t.test('can sort the keys at depth 3 or more too', function (st) {
  565. var sort = function (a, b) {
  566. return a.localeCompare(b);
  567. };
  568. st.equal(
  569. qs.stringify(
  570. { a: 'a', z: { zj: { zjb: 'zjb', zja: 'zja' }, zi: { zib: 'zib', zia: 'zia' } }, b: 'b' },
  571. { sort: sort, encode: false }
  572. ),
  573. 'a=a&b=b&z[zi][zia]=zia&z[zi][zib]=zib&z[zj][zja]=zja&z[zj][zjb]=zjb'
  574. );
  575. st.equal(
  576. qs.stringify(
  577. { a: 'a', z: { zj: { zjb: 'zjb', zja: 'zja' }, zi: { zib: 'zib', zia: 'zia' } }, b: 'b' },
  578. { sort: null, encode: false }
  579. ),
  580. 'a=a&z[zj][zjb]=zjb&z[zj][zja]=zja&z[zi][zib]=zib&z[zi][zia]=zia&b=b'
  581. );
  582. st.end();
  583. });
  584. t.test('can stringify with custom encoding', function (st) {
  585. st.equal(qs.stringify({ 県: '大阪府', '': '' }, {
  586. encoder: function (str) {
  587. if (str.length === 0) {
  588. return '';
  589. }
  590. var buf = iconv.encode(str, 'shiftjis');
  591. var result = [];
  592. for (var i = 0; i < buf.length; ++i) {
  593. result.push(buf.readUInt8(i).toString(16));
  594. }
  595. return '%' + result.join('%');
  596. }
  597. }), '%8c%a7=%91%e5%8d%e3%95%7b&=');
  598. st.end();
  599. });
  600. t.test('receives the default encoder as a second argument', function (st) {
  601. st.plan(2);
  602. qs.stringify({ a: 1 }, {
  603. encoder: function (str, defaultEncoder) {
  604. st.equal(defaultEncoder, utils.encode);
  605. }
  606. });
  607. st.end();
  608. });
  609. t.test('throws error with wrong encoder', function (st) {
  610. st['throws'](function () {
  611. qs.stringify({}, { encoder: 'string' });
  612. }, new TypeError('Encoder has to be a function.'));
  613. st.end();
  614. });
  615. t.test('can use custom encoder for a buffer object', { skip: typeof Buffer === 'undefined' }, function (st) {
  616. st.equal(qs.stringify({ a: SaferBuffer.from([1]) }, {
  617. encoder: function (buffer) {
  618. if (typeof buffer === 'string') {
  619. return buffer;
  620. }
  621. return String.fromCharCode(buffer.readUInt8(0) + 97);
  622. }
  623. }), 'a=b');
  624. st.equal(qs.stringify({ a: SaferBuffer.from('a b') }, {
  625. encoder: function (buffer) {
  626. return buffer;
  627. }
  628. }), 'a=a b');
  629. st.end();
  630. });
  631. t.test('serializeDate option', function (st) {
  632. var date = new Date();
  633. st.equal(
  634. qs.stringify({ a: date }),
  635. 'a=' + date.toISOString().replace(/:/g, '%3A'),
  636. 'default is toISOString'
  637. );
  638. var mutatedDate = new Date();
  639. mutatedDate.toISOString = function () {
  640. throw new SyntaxError();
  641. };
  642. st['throws'](function () {
  643. mutatedDate.toISOString();
  644. }, SyntaxError);
  645. st.equal(
  646. qs.stringify({ a: mutatedDate }),
  647. 'a=' + Date.prototype.toISOString.call(mutatedDate).replace(/:/g, '%3A'),
  648. 'toISOString works even when method is not locally present'
  649. );
  650. var specificDate = new Date(6);
  651. st.equal(
  652. qs.stringify(
  653. { a: specificDate },
  654. { serializeDate: function (d) { return d.getTime() * 7; } }
  655. ),
  656. 'a=42',
  657. 'custom serializeDate function called'
  658. );
  659. st.equal(
  660. qs.stringify(
  661. { a: [date] },
  662. {
  663. serializeDate: function (d) { return d.getTime(); },
  664. arrayFormat: 'comma'
  665. }
  666. ),
  667. 'a=' + date.getTime(),
  668. 'works with arrayFormat comma'
  669. );
  670. st.equal(
  671. qs.stringify(
  672. { a: [date] },
  673. {
  674. serializeDate: function (d) { return d.getTime(); },
  675. arrayFormat: 'comma',
  676. commaRoundTrip: true
  677. }
  678. ),
  679. 'a%5B%5D=' + date.getTime(),
  680. 'works with arrayFormat comma'
  681. );
  682. st.end();
  683. });
  684. t.test('RFC 1738 serialization', function (st) {
  685. st.equal(qs.stringify({ a: 'b c' }, { format: qs.formats.RFC1738 }), 'a=b+c');
  686. st.equal(qs.stringify({ 'a b': 'c d' }, { format: qs.formats.RFC1738 }), 'a+b=c+d');
  687. st.equal(qs.stringify({ 'a b': SaferBuffer.from('a b') }, { format: qs.formats.RFC1738 }), 'a+b=a+b');
  688. st.equal(qs.stringify({ 'foo(ref)': 'bar' }, { format: qs.formats.RFC1738 }), 'foo(ref)=bar');
  689. st.end();
  690. });
  691. t.test('RFC 3986 spaces serialization', function (st) {
  692. st.equal(qs.stringify({ a: 'b c' }, { format: qs.formats.RFC3986 }), 'a=b%20c');
  693. st.equal(qs.stringify({ 'a b': 'c d' }, { format: qs.formats.RFC3986 }), 'a%20b=c%20d');
  694. st.equal(qs.stringify({ 'a b': SaferBuffer.from('a b') }, { format: qs.formats.RFC3986 }), 'a%20b=a%20b');
  695. st.end();
  696. });
  697. t.test('Backward compatibility to RFC 3986', function (st) {
  698. st.equal(qs.stringify({ a: 'b c' }), 'a=b%20c');
  699. st.equal(qs.stringify({ 'a b': SaferBuffer.from('a b') }), 'a%20b=a%20b');
  700. st.end();
  701. });
  702. t.test('Edge cases and unknown formats', function (st) {
  703. ['UFO1234', false, 1234, null, {}, []].forEach(function (format) {
  704. st['throws'](
  705. function () {
  706. qs.stringify({ a: 'b c' }, { format: format });
  707. },
  708. new TypeError('Unknown format option provided.')
  709. );
  710. });
  711. st.end();
  712. });
  713. t.test('encodeValuesOnly', function (st) {
  714. st.equal(
  715. qs.stringify(
  716. { a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
  717. { encodeValuesOnly: true }
  718. ),
  719. 'a=b&c[0]=d&c[1]=e%3Df&f[0][0]=g&f[1][0]=h'
  720. );
  721. st.equal(
  722. qs.stringify(
  723. { a: 'b', c: ['d', 'e'], f: [['g'], ['h']] }
  724. ),
  725. 'a=b&c%5B0%5D=d&c%5B1%5D=e&f%5B0%5D%5B0%5D=g&f%5B1%5D%5B0%5D=h'
  726. );
  727. st.end();
  728. });
  729. t.test('encodeValuesOnly - strictNullHandling', function (st) {
  730. st.equal(
  731. qs.stringify(
  732. { a: { b: null } },
  733. { encodeValuesOnly: true, strictNullHandling: true }
  734. ),
  735. 'a[b]'
  736. );
  737. st.end();
  738. });
  739. t.test('throws if an invalid charset is specified', function (st) {
  740. st['throws'](function () {
  741. qs.stringify({ a: 'b' }, { charset: 'foobar' });
  742. }, new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined'));
  743. st.end();
  744. });
  745. t.test('respects a charset of iso-8859-1', function (st) {
  746. st.equal(qs.stringify({ æ: 'æ' }, { charset: 'iso-8859-1' }), '%E6=%E6');
  747. st.end();
  748. });
  749. t.test('encodes unrepresentable chars as numeric entities in iso-8859-1 mode', function (st) {
  750. st.equal(qs.stringify({ a: '☺' }, { charset: 'iso-8859-1' }), 'a=%26%239786%3B');
  751. st.end();
  752. });
  753. t.test('respects an explicit charset of utf-8 (the default)', function (st) {
  754. st.equal(qs.stringify({ a: 'æ' }, { charset: 'utf-8' }), 'a=%C3%A6');
  755. st.end();
  756. });
  757. t.test('adds the right sentinel when instructed to and the charset is utf-8', function (st) {
  758. st.equal(qs.stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'utf-8' }), 'utf8=%E2%9C%93&a=%C3%A6');
  759. st.end();
  760. });
  761. t.test('adds the right sentinel when instructed to and the charset is iso-8859-1', function (st) {
  762. st.equal(qs.stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'iso-8859-1' }), 'utf8=%26%2310003%3B&a=%E6');
  763. st.end();
  764. });
  765. t.test('does not mutate the options argument', function (st) {
  766. var options = {};
  767. qs.stringify({}, options);
  768. st.deepEqual(options, {});
  769. st.end();
  770. });
  771. t.test('strictNullHandling works with custom filter', function (st) {
  772. var filter = function (prefix, value) {
  773. return value;
  774. };
  775. var options = { strictNullHandling: true, filter: filter };
  776. st.equal(qs.stringify({ key: null }, options), 'key');
  777. st.end();
  778. });
  779. t.test('strictNullHandling works with null serializeDate', function (st) {
  780. var serializeDate = function () {
  781. return null;
  782. };
  783. var options = { strictNullHandling: true, serializeDate: serializeDate };
  784. var date = new Date();
  785. st.equal(qs.stringify({ key: date }, options), 'key');
  786. st.end();
  787. });
  788. t.test('allows for encoding keys and values differently', function (st) {
  789. var encoder = function (str, defaultEncoder, charset, type) {
  790. if (type === 'key') {
  791. return defaultEncoder(str, defaultEncoder, charset, type).toLowerCase();
  792. }
  793. if (type === 'value') {
  794. return defaultEncoder(str, defaultEncoder, charset, type).toUpperCase();
  795. }
  796. throw 'this should never happen! type: ' + type;
  797. };
  798. st.deepEqual(qs.stringify({ KeY: 'vAlUe' }, { encoder: encoder }), 'key=VALUE');
  799. st.end();
  800. });
  801. t.test('objects inside arrays', function (st) {
  802. var obj = { a: { b: { c: 'd', e: 'f' } } };
  803. var withArray = { a: { b: [{ c: 'd', e: 'f' }] } };
  804. st.equal(qs.stringify(obj, { encode: false }), 'a[b][c]=d&a[b][e]=f', 'no array, no arrayFormat');
  805. st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'bracket' }), 'a[b][c]=d&a[b][e]=f', 'no array, bracket');
  806. st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'indices' }), 'a[b][c]=d&a[b][e]=f', 'no array, indices');
  807. st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'comma' }), 'a[b][c]=d&a[b][e]=f', 'no array, comma');
  808. st.equal(qs.stringify(withArray, { encode: false }), 'a[b][0][c]=d&a[b][0][e]=f', 'array, no arrayFormat');
  809. st.equal(qs.stringify(withArray, { encode: false, arrayFormat: 'bracket' }), 'a[b][0][c]=d&a[b][0][e]=f', 'array, bracket');
  810. st.equal(qs.stringify(withArray, { encode: false, arrayFormat: 'indices' }), 'a[b][0][c]=d&a[b][0][e]=f', 'array, indices');
  811. st.equal(
  812. qs.stringify(withArray, { encode: false, arrayFormat: 'comma' }),
  813. '???',
  814. 'array, comma',
  815. { skip: 'TODO: figure out what this should do' }
  816. );
  817. st.end();
  818. });
  819. t.test('stringifies sparse arrays', function (st) {
  820. /* eslint no-sparse-arrays: 0 */
  821. st.equal(qs.stringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true }), 'a[1]=2&a[4]=1');
  822. st.equal(qs.stringify({ a: [, { b: [, , { c: '1' }] }] }, { encodeValuesOnly: true }), 'a[1][b][2][c]=1');
  823. st.equal(qs.stringify({ a: [, [, , [, , , { c: '1' }]]] }, { encodeValuesOnly: true }), 'a[1][2][3][c]=1');
  824. st.equal(qs.stringify({ a: [, [, , [, , , { c: [, '1'] }]]] }, { encodeValuesOnly: true }), 'a[1][2][3][c][1]=1');
  825. st.end();
  826. });
  827. t.end();
  828. });