Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: comma separated arrays not parsed correctly from encoded url #388

Closed
JH1ller opened this issue Jul 26, 2024 · 1 comment · Fixed by #392
Closed

Bug: comma separated arrays not parsed correctly from encoded url #388

JH1ller opened this issue Jul 26, 2024 · 1 comment · Fixed by #392

Comments

@JH1ller
Copy link

JH1ller commented Jul 26, 2024

Test case:

it('should parse arrays correctly', () => {
    const search =
      '?testA%5B%5D=1&testB%5B%5D=a%2Cb%2Cc%2Cd%2Ce%2Cf&testC=true';

    const result = queryString.parse(search, {
      parseBooleans: true,
      parseNumbers: true,
      arrayFormat: 'bracket-separator',
    });

    expect(result).toEqual({
      testA: [1],
      testB: ['a', 'b', 'c', 'd', 'e', 'f'],
      testC: true,
    });
  });

results in:

image

when it's unencoded it works fine:

it('should parse arrays correctly', () => {
    const search =
      '?testA%5B%5D=1&testB%5B%5D=a,b,c,d,e,f&testC=true';

    const result = queryString.parse(search, {
      parseBooleans: true,
      parseNumbers: true,
      arrayFormat: 'bracket-separator',
    });

    expect(result).toEqual({
      testA: [1],
      testB: ['a', 'b', 'c', 'd', 'e', 'f'],
      testC: true,
    });
  });

Library version: 9.1.0

@scottenock
Copy link
Contributor

Good spot, thanks for raising. @sindresorhus I have raised #392 which should fix this regression 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants