nock mixes usage of qs and querystring

Created on 22 Mar 2016  路  7Comments  路  Source: nock/nock

It appears nock mixes usage of native node querystring module and npm installed qs module for parsing querystring-like objects.

In nock/lib/interceptor.js it requires qs (a dependency in package.json), but in nock/lib/match_body.js it requires querystring, the native node library.

These two libraries have different outputs. For example:

var query = require('querystring');
var qs = require('qs');

query.parse('a%5Bb%5D=test'); // => { 'a[b]': 'test' }
qs.parse('a%5Bb%5D=test'); // => { a: { b: 'test' } }

This means interceptors and body matchers have different behavior.

bug help wanted pinned released

Most helpful comment

Which dependency would be desirable to keep? 'querystring' or 'qs' ?

I think native 'querystring'

see https://github.com/nock/nock/pull/563#issuecomment-338104773

All 7 comments

@jeffora Good catch.

A PR would be welcome..

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We try to do our best, but nock is maintained by volunteers and there is only so much we can do at a time. Thank you for your contributions.

Which dependency would be desirable to keep? 'querystring' or 'qs' ?

Which dependency would be desirable to keep? 'querystring' or 'qs' ?

I think native 'querystring'

see https://github.com/nock/nock/pull/563#issuecomment-338104773

I think this is a good idea, though it will be a breaking change to body matching. For example, It will break use cases like this one:

https://github.com/nock/nock/blob/3d74a15cdbecf805400471c5bd0bbfeca4fa7b96/tests/test_body_match.js#L193-L222

I suggest we add a flag to allow users who use array syntax and qs-style encoding to keep using it. We could make qs an optionalDependency.

:tada: This issue has been resolved in version 11.0.0-beta.30 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

:tada: This issue has been resolved in version 11.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Was this page helpful?
0 / 5 - 0 ratings