question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parameter matching in routes fails with underscores

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kettanaitocommented, Sep 23, 2020

Thanks to @timdeschryver the issue has been fixed and published in node-match-path@0.5.1. If you re-install your dependencies the fix should propagate in.

1reaction
kettanaitocommented, Sep 22, 2020

@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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Underscore in URL not working with attribute routing
When I request /SiteCode, it works fine. When I include a parameter, such as /SiteCode/something, that too works fine. When the URL is...
Read more >
Regular Expressions
Pattern matching either succeeds or fails. For example, you can specify in an X.25 routing table that incoming packets with destination addresses beginning ......
Read more >
Regular Expressions :: Eloquent JavaScript
This problem occurs when a pattern can match a piece of input in many different ways. For example, if we get confused while...
Read more >
Bash Reference Manual - GNU.org
A word consisting solely of letters, numbers, and underscores, ... The first pattern that matches determines the command-list that is ...
Read more >
PEP 622 – Structural Pattern Matching
The wildcard pattern is a single underscore: _ . It always matches, but does not capture ... During failed pattern matches, some sub-patterns...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found