Skip to content

Commit

Permalink
fix(core): Strict null query param handling (#302)
Browse files Browse the repository at this point in the history
This helps differentiated between `?foo` and `?foo=` query params.
  • Loading branch information
offirgolan authored Jan 29, 2020
1 parent 7a3c06e commit 5cf70aa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/@pollyjs/utils/src/utils/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ function parseQuery(query, options) {
return qs.parse(query, {
plainObjects: true,
ignoreQueryPrefix: true,
strictNullHandling: true,
...options
});
}

function stringifyQuery(obj, options = {}) {
return qs.stringify(obj, { addQueryPrefix: true, ...options });
return qs.stringify(obj, {
addQueryPrefix: true,
strictNullHandling: true,
...options
});
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/@pollyjs/utils/tests/unit/utils/url-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('Unit | Utils | URL', function() {
it('should correctly parse query params', function() {
[
['', {}],
['a&b=', { a: null, b: '' }],
['foo=bar', { foo: 'bar' }],
['a[]=1&a[]=2', { a: ['1', '2'] }],
['a[1]=1&a[0]=2', { a: ['2', '1'] }],
Expand All @@ -33,6 +34,7 @@ describe('Unit | Utils | URL', function() {
[
// Query string will be undefined but we decode it in the assertion
[{}, decode(undefined)],
[{ a: null, b: '' }, 'a&b='],
[{ foo: 'bar' }, 'foo=bar'],
[{ a: ['1', '2'] }, 'a[0]=1&a[1]=2'],
[{ foo: { bar: { baz: '1' } } }, 'foo[bar][baz]=1']
Expand Down

0 comments on commit 5cf70aa

Please sign in to comment.