Msw: Parameter matching in routes fails with underscores

Created on 21 Sep 2020  路  5Comments  路  Source: mswjs/msw

Environment

| Name | Version |
| ---- | ------- |
| msw | 0.21.2 |
| node | 10.16.3 |
| OS | Windows 10 |

Request handlers

// Example of declaration. Provide your code here.
import { setupServer } from 'msw/node'
import { rest } from 'msw'

const server = setupServer(
  rest.get('/project/project_id', () => {
      // handle request
  })
)

server.listen()

Actual request

fetch('/project/4').then((res) => res.json())

Current behavior

Request fails to match.

Expected behavior

Request should be matched by msw.

Note switching the URL parameter name to be projectId results in the matching working as expected.
I could not see any restrictions on variable naming in the documentation hence raising the issue as it took quite a while to figure out why the request was not being matched and don't want others to fall into the same trap.

bug node

All 5 comments

Hey, @joe-hilling. Thanks for reporting this.

This is an issue in the node-match-path library responsible for request URL matching. We should tackle this in the nearest time. Would you be interested in issuing a pull request? I could then onboard you more in how it works and why there's an issue.

You can assign this one to me if @joe-hilling doesn't claim this issue.

Hi @kettanaito, I won't be able to take this on I am afraid. I am struggling to keep on top of my day job ATM. Also, am a bit of a hacker so probably not coding clean enough for production code.

Thanks to you and the team for library, it's saving my skin on a complex internal company project!

@joe-hilling, absolutely no worries! I'm already thankful for you finding and reporting this, you rock!

@timdeschryver, thanks for volunteering to battle this issue! I've created a task in the node-match-path repo (https://github.com/mswjs/node-match-path/issues/26). Would love to support you in this contribution. Looking forward to see the pull request!

Thanks to @timdeschryver the issue has been fixed and published in [email protected]. If you re-install your dependencies the fix should propagate in.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Afsoon picture Afsoon  路  3Comments

kettanaito picture kettanaito  路  3Comments

abrudin picture abrudin  路  3Comments

derekr picture derekr  路  3Comments

otaciliolacerda picture otaciliolacerda  路  3Comments