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

Fix stringify for bracket mode with arrays containing null #138

Merged
merged 1 commit into from
May 2, 2018

Conversation

dubzzz
Copy link
Contributor

@dubzzz dubzzz commented Apr 1, 2018

I ran into an unexpected behaviour while running property based tests against query-string.

The unexpected behaviour is the following: when the settings bracket is enabled, null values contained inside arrays are badly exported causing problems on parsing side

m.stringify({bar: ['a', null, 'b']}, {arrayFormat: 'bracket'}) //=> "bar[]=a&bar&bar[]=b"
m.parse('bar[]=a&bar&bar[]=b', {arrayFormat: 'bracket'}) //=> {bar: [null, 'b']}

The commit contains both:

  • the fix to serialize arrays correctly when enabling bracket mode
  • the unit tests to assess the behaviour is correct
  • the original property based test that detected the problem

@dubzzz
Copy link
Contributor Author

dubzzz commented Apr 18, 2018

@sindresorhus
I believe that it would be great to fix this issue. Fix in this very same PR, #138.
Without the fix parsing fails to read some query params it has itself generated.

Thanks in advance for your feedback

@sindresorhus sindresorhus merged commit e5a6c1f into sindresorhus:master May 2, 2018
@sindresorhus
Copy link
Owner

Good catch. Thank you! :)

@sindresorhus
Copy link
Owner

Any idea why the fastcheck test fails on Node.js 10? https://travis-ci.org/sindresorhus/query-string/jobs/374050952

@dubzzz
Copy link
Contributor Author

dubzzz commented May 2, 2018

I am gonna have a look to it. Seems that it encountered a counterexample.
I let you know as soon as I get more details.

@dubzzz
Copy link
Contributor Author

dubzzz commented May 2, 2018

Submitting a fix for this issue as soon as possible.
In my original test, I used the wrong type for the sort parameter.

@dubzzz
Copy link
Contributor Author

dubzzz commented May 2, 2018

In the log we can see that the failing case is:

  • obj = {}
  • opts = {"arrayFormat":"bracket","strict":false,"encode":false,"sort":true}

And that it caused the following error: TypeError: The comparison function must be either a function or undefined in sort

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 this pull request may close these issues.

2 participants