parse.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. 'use strict';
  2. var test = require('tape');
  3. var qs = require('../');
  4. var iconv = require('iconv-lite');
  5. test('parse()', function (t) {
  6. t.test('parses a simple string', function (st) {
  7. st.deepEqual(qs.parse('0=foo'), { 0: 'foo' });
  8. st.deepEqual(qs.parse('foo=c++'), { foo: 'c ' });
  9. st.deepEqual(qs.parse('a[>=]=23'), { a: { '>=': '23' } });
  10. st.deepEqual(qs.parse('a[<=>]==23'), { a: { '<=>': '=23' } });
  11. st.deepEqual(qs.parse('a[==]=23'), { a: { '==': '23' } });
  12. st.deepEqual(qs.parse('foo', { strictNullHandling: true }), { foo: null });
  13. st.deepEqual(qs.parse('foo'), { foo: '' });
  14. st.deepEqual(qs.parse('foo='), { foo: '' });
  15. st.deepEqual(qs.parse('foo=bar'), { foo: 'bar' });
  16. st.deepEqual(qs.parse(' foo = bar = baz '), { ' foo ': ' bar = baz ' });
  17. st.deepEqual(qs.parse('foo=bar=baz'), { foo: 'bar=baz' });
  18. st.deepEqual(qs.parse('foo=bar&bar=baz'), { foo: 'bar', bar: 'baz' });
  19. st.deepEqual(qs.parse('foo2=bar2&baz2='), { foo2: 'bar2', baz2: '' });
  20. st.deepEqual(qs.parse('foo=bar&baz', { strictNullHandling: true }), { foo: 'bar', baz: null });
  21. st.deepEqual(qs.parse('foo=bar&baz'), { foo: 'bar', baz: '' });
  22. st.deepEqual(qs.parse('cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World'), {
  23. cht: 'p3',
  24. chd: 't:60,40',
  25. chs: '250x100',
  26. chl: 'Hello|World'
  27. });
  28. st.end();
  29. });
  30. t.test('allows enabling dot notation', function (st) {
  31. st.deepEqual(qs.parse('a.b=c'), { 'a.b': 'c' });
  32. st.deepEqual(qs.parse('a.b=c', { allowDots: true }), { a: { b: 'c' } });
  33. st.end();
  34. });
  35. t.deepEqual(qs.parse('a[b]=c'), { a: { b: 'c' } }, 'parses a single nested string');
  36. t.deepEqual(qs.parse('a[b][c]=d'), { a: { b: { c: 'd' } } }, 'parses a double nested string');
  37. t.deepEqual(
  38. qs.parse('a[b][c][d][e][f][g][h]=i'),
  39. { a: { b: { c: { d: { e: { f: { '[g][h]': 'i' } } } } } } },
  40. 'defaults to a depth of 5'
  41. );
  42. t.test('only parses one level when depth = 1', function (st) {
  43. st.deepEqual(qs.parse('a[b][c]=d', { depth: 1 }), { a: { b: { '[c]': 'd' } } });
  44. st.deepEqual(qs.parse('a[b][c][d]=e', { depth: 1 }), { a: { b: { '[c][d]': 'e' } } });
  45. st.end();
  46. });
  47. t.deepEqual(qs.parse('a=b&a=c'), { a: ['b', 'c'] }, 'parses a simple array');
  48. t.test('parses an explicit array', function (st) {
  49. st.deepEqual(qs.parse('a[]=b'), { a: ['b'] });
  50. st.deepEqual(qs.parse('a[]=b&a[]=c'), { a: ['b', 'c'] });
  51. st.deepEqual(qs.parse('a[]=b&a[]=c&a[]=d'), { a: ['b', 'c', 'd'] });
  52. st.end();
  53. });
  54. t.test('parses a mix of simple and explicit arrays', function (st) {
  55. st.deepEqual(qs.parse('a=b&a[]=c'), { a: ['b', 'c'] });
  56. st.deepEqual(qs.parse('a[]=b&a=c'), { a: ['b', 'c'] });
  57. st.deepEqual(qs.parse('a[0]=b&a=c'), { a: ['b', 'c'] });
  58. st.deepEqual(qs.parse('a=b&a[0]=c'), { a: ['b', 'c'] });
  59. st.deepEqual(qs.parse('a[1]=b&a=c', { arrayLimit: 20 }), { a: ['b', 'c'] });
  60. st.deepEqual(qs.parse('a[]=b&a=c', { arrayLimit: 0 }), { a: ['b', 'c'] });
  61. st.deepEqual(qs.parse('a[]=b&a=c'), { a: ['b', 'c'] });
  62. st.deepEqual(qs.parse('a=b&a[1]=c', { arrayLimit: 20 }), { a: ['b', 'c'] });
  63. st.deepEqual(qs.parse('a=b&a[]=c', { arrayLimit: 0 }), { a: ['b', 'c'] });
  64. st.deepEqual(qs.parse('a=b&a[]=c'), { a: ['b', 'c'] });
  65. st.end();
  66. });
  67. t.test('parses a nested array', function (st) {
  68. st.deepEqual(qs.parse('a[b][]=c&a[b][]=d'), { a: { b: ['c', 'd'] } });
  69. st.deepEqual(qs.parse('a[>=]=25'), { a: { '>=': '25' } });
  70. st.end();
  71. });
  72. t.test('allows to specify array indices', function (st) {
  73. st.deepEqual(qs.parse('a[1]=c&a[0]=b&a[2]=d'), { a: ['b', 'c', 'd'] });
  74. st.deepEqual(qs.parse('a[1]=c&a[0]=b'), { a: ['b', 'c'] });
  75. st.deepEqual(qs.parse('a[1]=c', { arrayLimit: 20 }), { a: ['c'] });
  76. st.deepEqual(qs.parse('a[1]=c', { arrayLimit: 0 }), { a: { 1: 'c' } });
  77. st.deepEqual(qs.parse('a[1]=c'), { a: ['c'] });
  78. st.end();
  79. });
  80. t.test('limits specific array indices to arrayLimit', function (st) {
  81. st.deepEqual(qs.parse('a[20]=a', { arrayLimit: 20 }), { a: ['a'] });
  82. st.deepEqual(qs.parse('a[21]=a', { arrayLimit: 20 }), { a: { 21: 'a' } });
  83. st.end();
  84. });
  85. t.deepEqual(qs.parse('a[12b]=c'), { a: { '12b': 'c' } }, 'supports keys that begin with a number');
  86. t.test('supports encoded = signs', function (st) {
  87. st.deepEqual(qs.parse('he%3Dllo=th%3Dere'), { 'he=llo': 'th=ere' });
  88. st.end();
  89. });
  90. t.test('is ok with url encoded strings', function (st) {
  91. st.deepEqual(qs.parse('a[b%20c]=d'), { a: { 'b c': 'd' } });
  92. st.deepEqual(qs.parse('a[b]=c%20d'), { a: { b: 'c d' } });
  93. st.end();
  94. });
  95. t.test('allows brackets in the value', function (st) {
  96. st.deepEqual(qs.parse('pets=["tobi"]'), { pets: '["tobi"]' });
  97. st.deepEqual(qs.parse('operators=[">=", "<="]'), { operators: '[">=", "<="]' });
  98. st.end();
  99. });
  100. t.test('allows empty values', function (st) {
  101. st.deepEqual(qs.parse(''), {});
  102. st.deepEqual(qs.parse(null), {});
  103. st.deepEqual(qs.parse(undefined), {});
  104. st.end();
  105. });
  106. t.test('transforms arrays to objects', function (st) {
  107. st.deepEqual(qs.parse('foo[0]=bar&foo[bad]=baz'), { foo: { 0: 'bar', bad: 'baz' } });
  108. st.deepEqual(qs.parse('foo[bad]=baz&foo[0]=bar'), { foo: { bad: 'baz', 0: 'bar' } });
  109. st.deepEqual(qs.parse('foo[bad]=baz&foo[]=bar'), { foo: { bad: 'baz', 0: 'bar' } });
  110. st.deepEqual(qs.parse('foo[]=bar&foo[bad]=baz'), { foo: { 0: 'bar', bad: 'baz' } });
  111. st.deepEqual(qs.parse('foo[bad]=baz&foo[]=bar&foo[]=foo'), { foo: { bad: 'baz', 0: 'bar', 1: 'foo' } });
  112. st.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' }] });
  113. st.deepEqual(qs.parse('a[]=b&a[t]=u&a[hasOwnProperty]=c', { allowPrototypes: false }), { a: { 0: 'b', c: true, t: 'u' } });
  114. st.deepEqual(qs.parse('a[]=b&a[t]=u&a[hasOwnProperty]=c', { allowPrototypes: true }), { a: { 0: 'b', t: 'u', hasOwnProperty: 'c' } });
  115. st.deepEqual(qs.parse('a[]=b&a[hasOwnProperty]=c&a[x]=y', { allowPrototypes: false }), { a: { 0: 'b', 1: 'c', x: 'y' } });
  116. st.deepEqual(qs.parse('a[]=b&a[hasOwnProperty]=c&a[x]=y', { allowPrototypes: true }), { a: { 0: 'b', hasOwnProperty: 'c', x: 'y' } });
  117. st.end();
  118. });
  119. t.test('transforms arrays to objects (dot notation)', function (st) {
  120. st.deepEqual(qs.parse('foo[0].baz=bar&fool.bad=baz', { allowDots: true }), { foo: [{ baz: 'bar' }], fool: { bad: 'baz' } });
  121. st.deepEqual(qs.parse('foo[0].baz=bar&fool.bad.boo=baz', { allowDots: true }), { foo: [{ baz: 'bar' }], fool: { bad: { boo: 'baz' } } });
  122. st.deepEqual(qs.parse('foo[0][0].baz=bar&fool.bad=baz', { allowDots: true }), { foo: [[{ baz: 'bar' }]], fool: { bad: 'baz' } });
  123. st.deepEqual(qs.parse('foo[0].baz[0]=15&foo[0].bar=2', { allowDots: true }), { foo: [{ baz: ['15'], bar: '2' }] });
  124. st.deepEqual(qs.parse('foo[0].baz[0]=15&foo[0].baz[1]=16&foo[0].bar=2', { allowDots: true }), { foo: [{ baz: ['15', '16'], bar: '2' }] });
  125. st.deepEqual(qs.parse('foo.bad=baz&foo[0]=bar', { allowDots: true }), { foo: { bad: 'baz', 0: 'bar' } });
  126. st.deepEqual(qs.parse('foo.bad=baz&foo[]=bar', { allowDots: true }), { foo: { bad: 'baz', 0: 'bar' } });
  127. st.deepEqual(qs.parse('foo[]=bar&foo.bad=baz', { allowDots: true }), { foo: { 0: 'bar', bad: 'baz' } });
  128. st.deepEqual(qs.parse('foo.bad=baz&foo[]=bar&foo[]=foo', { allowDots: true }), { foo: { bad: 'baz', 0: 'bar', 1: 'foo' } });
  129. st.deepEqual(qs.parse('foo[0].a=a&foo[0].b=b&foo[1].a=aa&foo[1].b=bb', { allowDots: true }), { foo: [{ a: 'a', b: 'b' }, { a: 'aa', b: 'bb' }] });
  130. st.end();
  131. });
  132. t.deepEqual(qs.parse('a[b]=c&a=d'), { a: { b: 'c', d: true } }, 'can add keys to objects');
  133. t.test('correctly prunes undefined values when converting an array to an object', function (st) {
  134. st.deepEqual(qs.parse('a[2]=b&a[99999999]=c'), { a: { 2: 'b', 99999999: 'c' } });
  135. st.end();
  136. });
  137. t.test('supports malformed uri characters', function (st) {
  138. st.deepEqual(qs.parse('{%:%}', { strictNullHandling: true }), { '{%:%}': null });
  139. st.deepEqual(qs.parse('{%:%}='), { '{%:%}': '' });
  140. st.deepEqual(qs.parse('foo=%:%}'), { foo: '%:%}' });
  141. st.end();
  142. });
  143. t.test('doesn\'t produce empty keys', function (st) {
  144. st.deepEqual(qs.parse('_r=1&'), { _r: '1' });
  145. st.end();
  146. });
  147. t.test('cannot access Object prototype', function (st) {
  148. qs.parse('constructor[prototype][bad]=bad');
  149. qs.parse('bad[constructor][prototype][bad]=bad');
  150. st.equal(typeof Object.prototype.bad, 'undefined');
  151. st.end();
  152. });
  153. t.test('parses arrays of objects', function (st) {
  154. st.deepEqual(qs.parse('a[][b]=c'), { a: [{ b: 'c' }] });
  155. st.deepEqual(qs.parse('a[0][b]=c'), { a: [{ b: 'c' }] });
  156. st.end();
  157. });
  158. t.test('allows for empty strings in arrays', function (st) {
  159. st.deepEqual(qs.parse('a[]=b&a[]=&a[]=c'), { a: ['b', '', 'c'] });
  160. st.deepEqual(
  161. qs.parse('a[0]=b&a[1]&a[2]=c&a[19]=', { strictNullHandling: true, arrayLimit: 20 }),
  162. { a: ['b', null, 'c', ''] },
  163. 'with arrayLimit 20 + array indices: null then empty string works'
  164. );
  165. st.deepEqual(
  166. qs.parse('a[]=b&a[]&a[]=c&a[]=', { strictNullHandling: true, arrayLimit: 0 }),
  167. { a: ['b', null, 'c', ''] },
  168. 'with arrayLimit 0 + array brackets: null then empty string works'
  169. );
  170. st.deepEqual(
  171. qs.parse('a[0]=b&a[1]=&a[2]=c&a[19]', { strictNullHandling: true, arrayLimit: 20 }),
  172. { a: ['b', '', 'c', null] },
  173. 'with arrayLimit 20 + array indices: empty string then null works'
  174. );
  175. st.deepEqual(
  176. qs.parse('a[]=b&a[]=&a[]=c&a[]', { strictNullHandling: true, arrayLimit: 0 }),
  177. { a: ['b', '', 'c', null] },
  178. 'with arrayLimit 0 + array brackets: empty string then null works'
  179. );
  180. st.deepEqual(
  181. qs.parse('a[]=&a[]=b&a[]=c'),
  182. { a: ['', 'b', 'c'] },
  183. 'array brackets: empty strings work'
  184. );
  185. st.end();
  186. });
  187. t.test('compacts sparse arrays', function (st) {
  188. st.deepEqual(qs.parse('a[10]=1&a[2]=2', { arrayLimit: 20 }), { a: ['2', '1'] });
  189. st.deepEqual(qs.parse('a[1][b][2][c]=1', { arrayLimit: 20 }), { a: [{ b: [{ c: '1' }] }] });
  190. st.deepEqual(qs.parse('a[1][2][3][c]=1', { arrayLimit: 20 }), { a: [[[{ c: '1' }]]] });
  191. st.deepEqual(qs.parse('a[1][2][3][c][1]=1', { arrayLimit: 20 }), { a: [[[{ c: ['1'] }]]] });
  192. st.end();
  193. });
  194. t.test('parses semi-parsed strings', function (st) {
  195. st.deepEqual(qs.parse({ 'a[b]': 'c' }), { a: { b: 'c' } });
  196. st.deepEqual(qs.parse({ 'a[b]': 'c', 'a[d]': 'e' }), { a: { b: 'c', d: 'e' } });
  197. st.end();
  198. });
  199. t.test('parses buffers correctly', function (st) {
  200. var b = new Buffer('test');
  201. st.deepEqual(qs.parse({ a: b }), { a: b });
  202. st.end();
  203. });
  204. t.test('continues parsing when no parent is found', function (st) {
  205. st.deepEqual(qs.parse('[]=&a=b'), { 0: '', a: 'b' });
  206. st.deepEqual(qs.parse('[]&a=b', { strictNullHandling: true }), { 0: null, a: 'b' });
  207. st.deepEqual(qs.parse('[foo]=bar'), { foo: 'bar' });
  208. st.end();
  209. });
  210. t.test('does not error when parsing a very long array', function (st) {
  211. var str = 'a[]=a';
  212. while (Buffer.byteLength(str) < 128 * 1024) {
  213. str = str + '&' + str;
  214. }
  215. st.doesNotThrow(function () {
  216. qs.parse(str);
  217. });
  218. st.end();
  219. });
  220. t.test('should not throw when a native prototype has an enumerable property', { parallel: false }, function (st) {
  221. Object.prototype.crash = '';
  222. Array.prototype.crash = '';
  223. st.doesNotThrow(qs.parse.bind(null, 'a=b'));
  224. st.deepEqual(qs.parse('a=b'), { a: 'b' });
  225. st.doesNotThrow(qs.parse.bind(null, 'a[][b]=c'));
  226. st.deepEqual(qs.parse('a[][b]=c'), { a: [{ b: 'c' }] });
  227. delete Object.prototype.crash;
  228. delete Array.prototype.crash;
  229. st.end();
  230. });
  231. t.test('parses a string with an alternative string delimiter', function (st) {
  232. st.deepEqual(qs.parse('a=b;c=d', { delimiter: ';' }), { a: 'b', c: 'd' });
  233. st.end();
  234. });
  235. t.test('parses a string with an alternative RegExp delimiter', function (st) {
  236. st.deepEqual(qs.parse('a=b; c=d', { delimiter: /[;,] */ }), { a: 'b', c: 'd' });
  237. st.end();
  238. });
  239. t.test('does not use non-splittable objects as delimiters', function (st) {
  240. st.deepEqual(qs.parse('a=b&c=d', { delimiter: true }), { a: 'b', c: 'd' });
  241. st.end();
  242. });
  243. t.test('allows overriding parameter limit', function (st) {
  244. st.deepEqual(qs.parse('a=b&c=d', { parameterLimit: 1 }), { a: 'b' });
  245. st.end();
  246. });
  247. t.test('allows setting the parameter limit to Infinity', function (st) {
  248. st.deepEqual(qs.parse('a=b&c=d', { parameterLimit: Infinity }), { a: 'b', c: 'd' });
  249. st.end();
  250. });
  251. t.test('allows overriding array limit', function (st) {
  252. st.deepEqual(qs.parse('a[0]=b', { arrayLimit: -1 }), { a: { 0: 'b' } });
  253. st.deepEqual(qs.parse('a[-1]=b', { arrayLimit: -1 }), { a: { '-1': 'b' } });
  254. st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayLimit: 0 }), { a: { 0: 'b', 1: 'c' } });
  255. st.end();
  256. });
  257. t.test('allows disabling array parsing', function (st) {
  258. st.deepEqual(qs.parse('a[0]=b&a[1]=c', { parseArrays: false }), { a: { 0: 'b', 1: 'c' } });
  259. st.end();
  260. });
  261. t.test('parses an object', function (st) {
  262. var input = {
  263. 'user[name]': { 'pop[bob]': 3 },
  264. 'user[email]': null
  265. };
  266. var expected = {
  267. user: {
  268. name: { 'pop[bob]': 3 },
  269. email: null
  270. }
  271. };
  272. var result = qs.parse(input);
  273. st.deepEqual(result, expected);
  274. st.end();
  275. });
  276. t.test('parses an object in dot notation', function (st) {
  277. var input = {
  278. 'user.name': { 'pop[bob]': 3 },
  279. 'user.email.': null
  280. };
  281. var expected = {
  282. user: {
  283. name: { 'pop[bob]': 3 },
  284. email: null
  285. }
  286. };
  287. var result = qs.parse(input, { allowDots: true });
  288. st.deepEqual(result, expected);
  289. st.end();
  290. });
  291. t.test('parses an object and not child values', function (st) {
  292. var input = {
  293. 'user[name]': { 'pop[bob]': { test: 3 } },
  294. 'user[email]': null
  295. };
  296. var expected = {
  297. user: {
  298. name: { 'pop[bob]': { test: 3 } },
  299. email: null
  300. }
  301. };
  302. var result = qs.parse(input);
  303. st.deepEqual(result, expected);
  304. st.end();
  305. });
  306. t.test('does not blow up when Buffer global is missing', function (st) {
  307. var tempBuffer = global.Buffer;
  308. delete global.Buffer;
  309. var result = qs.parse('a=b&c=d');
  310. global.Buffer = tempBuffer;
  311. st.deepEqual(result, { a: 'b', c: 'd' });
  312. st.end();
  313. });
  314. t.test('does not crash when parsing circular references', function (st) {
  315. var a = {};
  316. a.b = a;
  317. var parsed;
  318. st.doesNotThrow(function () {
  319. parsed = qs.parse({ 'foo[bar]': 'baz', 'foo[baz]': a });
  320. });
  321. st.equal('foo' in parsed, true, 'parsed has "foo" property');
  322. st.equal('bar' in parsed.foo, true);
  323. st.equal('baz' in parsed.foo, true);
  324. st.equal(parsed.foo.bar, 'baz');
  325. st.deepEqual(parsed.foo.baz, a);
  326. st.end();
  327. });
  328. t.test('parses null objects correctly', { skip: !Object.create }, function (st) {
  329. var a = Object.create(null);
  330. a.b = 'c';
  331. st.deepEqual(qs.parse(a), { b: 'c' });
  332. var result = qs.parse({ a: a });
  333. st.equal('a' in result, true, 'result has "a" property');
  334. st.deepEqual(result.a, a);
  335. st.end();
  336. });
  337. t.test('parses dates correctly', function (st) {
  338. var now = new Date();
  339. st.deepEqual(qs.parse({ a: now }), { a: now });
  340. st.end();
  341. });
  342. t.test('parses regular expressions correctly', function (st) {
  343. var re = /^test$/;
  344. st.deepEqual(qs.parse({ a: re }), { a: re });
  345. st.end();
  346. });
  347. t.test('can allow overwriting prototype properties', function (st) {
  348. st.deepEqual(qs.parse('a[hasOwnProperty]=b', { allowPrototypes: true }), { a: { hasOwnProperty: 'b' } }, { prototype: false });
  349. st.deepEqual(qs.parse('hasOwnProperty=b', { allowPrototypes: true }), { hasOwnProperty: 'b' }, { prototype: false });
  350. st.end();
  351. });
  352. t.test('can return null objects', { skip: !Object.create }, function (st) {
  353. var expected = Object.create(null);
  354. expected.a = Object.create(null);
  355. expected.a.b = 'c';
  356. expected.a.hasOwnProperty = 'd';
  357. st.deepEqual(qs.parse('a[b]=c&a[hasOwnProperty]=d', { plainObjects: true }), expected);
  358. st.deepEqual(qs.parse(null, { plainObjects: true }), Object.create(null));
  359. var expectedArray = Object.create(null);
  360. expectedArray.a = Object.create(null);
  361. expectedArray.a[0] = 'b';
  362. expectedArray.a.c = 'd';
  363. st.deepEqual(qs.parse('a[]=b&a[c]=d', { plainObjects: true }), expectedArray);
  364. st.end();
  365. });
  366. t.test('can parse with custom encoding', function (st) {
  367. st.deepEqual(qs.parse('%8c%a7=%91%e5%8d%e3%95%7b', {
  368. decoder: function (str) {
  369. var reg = /%([0-9A-F]{2})/ig;
  370. var result = [];
  371. var parts = reg.exec(str);
  372. while (parts) {
  373. result.push(parseInt(parts[1], 16));
  374. parts = reg.exec(str);
  375. }
  376. return iconv.decode(new Buffer(result), 'shift_jis').toString();
  377. }
  378. }), { 県: '大阪府' });
  379. st.end();
  380. });
  381. t.test('throws error with wrong decoder', function (st) {
  382. st.throws(function () {
  383. qs.parse({}, { decoder: 'string' });
  384. }, new TypeError('Decoder has to be a function.'));
  385. st.end();
  386. });
  387. });