Msw: Request matches when request paths has same suffix

Created on 3 Nov 2020  路  5Comments  路  Source: mswjs/msw

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

bug

Most helpful comment

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 /

All 5 comments

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 /

The fix from @marcosvega91 has been published in [email protected].

@pkkummermo could you please re-install your project's dependencies (npm install --force) and let us know that the issue is fixed? Thanks.

@kettanaito
No go, but the package-lock of msw says

"node-match-path": "^0.4.4",

Which I guess means that it will only keep bumping patches, not minors.

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

Thank you so much for the quick fix :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

otaciliolacerda picture otaciliolacerda  路  3Comments

slowselfip picture slowselfip  路  3Comments

lukesmurray picture lukesmurray  路  3Comments

otaciliolacerda picture otaciliolacerda  路  3Comments

dashed picture dashed  路  3Comments