Closed Ari-ZH closed 1 month ago
Here is the test code: when strictNullHandling and allowEmptyArrays are both set to true, the parse function does not correctly interpret the result of stringify.
strictNullHandling
allowEmptyArrays
import { expect, test } from 'vitest'; import qs from 'qs'; const beforeParams = { testEmptyArray: [], }; // stringify result const searchStr = 'testEmptyArray[]'; // expect parse result const afterParams = { testEmptyArray: [], }; test('stringify', () => { expect( qs.stringify(beforeParams, { strictNullHandling: true, allowEmptyArrays: true, }), ).toBe(searchStr); }); test('parseSearchStr', () => { expect( qs.parse(searchStr, { strictNullHandling: true, allowEmptyArrays: true }), ).toStrictEqual(afterParams); // expect { testEmptyArray:[] } but return { testEmptyArray:[null] } });
Version: 6.12.2
I believe the issue arises here. https://github.com/ljharb/qs/blob/main/lib/parse.js#L129 leaf is null when strictNullHandling is true , so it return [null]
Thanks, this is very helpful.
Here is the test code: when
strictNullHandling
andallowEmptyArrays
are both set to true, the parse function does not correctly interpret the result of stringify.Version: 6.12.2