mswjs / node-match-path Goto Github PK
View Code? Open in Web Editor NEWMatches a URL against a path. Parameters, wildcards, RegExp.
Home Page: https://npmjs.com/package/node-match-path
Matches a URL against a path. Parameters, wildcards, RegExp.
Home Page: https://npmjs.com/package/node-match-path
I haven't tested this extensively, but I'm using this library via MSW and I think I've found a fairly common use case that is not supported. Specifically, this library will not handle a url like
/api/books/:bookId.json.
In manually inspecting this file https://github.com/mswjs/node-match-path/blob/master/src/pathToRegExp.ts, I believe the problem is that line 19 does not include a "." in the list of characters to terminate the parameter match.
I'll try to submit a pull request and appropriate tests in the next day or so, but figured I'd go ahead and report the issue.
Currently the library uses its own abstraction to provide similar test assertions for different input data.
Consider jest.each
or jest-in-case
instead.
Given user/:userId/*
path it must match the url: /user/abc/messages
.
Named capture groups are not currently supported in the latest release of Firefox (77). They will never be supported in IE. They have no support in Firefox for Android.
Question marks in the string path are returned as-is, creating a logical RegExp operator.
Question marks in the string path are escaped: \?
.
match('/user/:userId', '/user/abc-123?hello=true')
{ params: { userId: 'abc-123?hello=true' } }
{ params: { userId: 'abc-123' } }
Query parameter must be disregarded during path parameter match.
Currently the RegExp for path parameter names does not account for the underscore character "_". This produces falsely negative path matches for paths that include parameters that contain underscores.
match('/user/:user_id', '/user/1')
// no match
match('/user/:user_id', 'user/1')
// { matches: true, params: { user_id: 1 } }
Expected: /foo
Actual: /Foo
Result: no match.
Should behave as ExpressJS path matching in terms of case-sensitivity.
Expected: /foo
Actual: /Foo
Actual: /foo
Result: matches.
const path = '/image/:transforms?/:version?/:id'
match(path, '/image/a,b,c/1.2.3/id') // { params: { transforms: 'a,b,c', version: '1.2.3', id: 'id' } }
match(path, '/image/a,b,c/id') // { params: { transforms: 'a,b,c', version: null, id: 'id' } }
match(path, '/image/id') // { params: { transforms: null, version: null, id: 'id' } }
Reproduce this behavior in the Express Route Tester.
/user/details*
Matches: /user/details0
Doesn't match: /user/details
Matches: /user/details
and /user/details0
This is the behavior exhibited by ExpressJS, we should respect that.
Consider this usage example:
import { match } from 'node-match-path'
match('https://test.msw.io', 'https://test.msw.io/')
The given path won't match the expected path.
Trailing slash is ignored when matching paths.
Trailing slash is often appended by the client automatically. For example, executing fetch('https://test.msw.io')
would perform an actual request to https://test.msw.io/
.
I think the library should support RegExp supplied as the path
argument in order to be compatible with path-to-regexp
. Since the given string path is converted to a RegExp, handling an explicit RegExp won't be a big problem.
/user/:u
Does not create a u
parameter at all. Maybe be an issue in how RegExp is constructed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.