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.

Request matches when request paths has same suffix

See original GitHub issue

Describe the bug

If the suffix matches, a request is mocked with the value between the suffix and path param. This leads to me not being able to have

/users/1/somepath and /users/somepath

as both of these match. The temporary fix is to change the order of these, but that’s not really the correct answer to this.

Environment

Browser

  • msw: 0.21.3
  • nodejs: 13.14.0
  • npm: 6.14.4

To Reproduce

Steps to reproduce the behavior:

  1. Go to https://mswjs.io/docs/basics/request-matching
  2. Write /user/:userId/endofpath in Request handler URL and /user/0251e7ac/test/abc/endofpath in Actual request URL
  3. See that it matches the path between.

Expected behavior

It should not match

Screenshots

image

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
marcosvega91commented, Nov 3, 2020

Hi @pkkummermo thanks for raising this 😃.

What you are saying is correct, thanks !!! I’ll fix in a while 😃.

The issue is causing by https://github.com/mswjs/node-match-path/blob/e1e0fac2c335629ac1dd345c297e76d5ea922c92/src/pathToRegExp.ts#L18-L20 because we are not removing /

1reaction
kettanaitocommented, Nov 3, 2020

Thanks for letting me know. The fix will propagate in the next release of msw then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: Re: how to match regardless whether there is a tra...
I have an issue while defining a resource in my api proxy. I want to allow only POST requests if the path suffix...
Read more >
Request Matching Logic
The general rule for matching request to endpoint definition is “take first endpoint that fully matches criteria”. This means that there can be...
Read more >
Rest query working for all suffix inputs after matching path ...
I have configured REST with Camel. In that I have successfully get response from writen APIs. my problem is that given api works...
Read more >
URL Matching with PathPattern in Spring MVC
We could leave the request path encoded via UrlPathHelper#urlDecode but then we can't use a prefix Servlet mapping because the servletPath ...
Read more >
Strip part of a path prefix when routing - Questions
A root path like /my-service with strip_path set to true results in an upstream request with a path of / , and isn't...
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