Skip to content

Query params: Arrays and comma-separated strings are equal #1552

@jonogilmour

Description

@jonogilmour

What is the expected behavior?
Nock should not consider comma-separated query params to match array-based query params
What is the actual behavior?
If nock expects a comma-separated string as a query parameter, and an array-based parameter is set in the tested code, the two params are seen to be equal.
Possible solution
The problem, I believe, happens in matchStringOrRegexp. The interceptor sees the expected value is the comma-separated string (a string), it passes that and the qs.parsed query param (an array) to matchStringOrRegexp. matchStringOrRegexp will typecast the array to a string, meaning they will match:

matchStringOrRegexp([ 'abc', '123' ], 'abc,123') => true

How to reproduce the issue

https://runkit.com/jonogilmour/node-nock-query-issue

Does the bug have a test case?

Versions

Software Version(s)
Nock 10.0.0
Node 8.12.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions