@@ -260,6 +260,33 @@ export class RegexPathMatcher extends Serializable implements RequestMatcher {
260260
261261}
262262
263+ export class RegexUrlMatcher extends Serializable implements RequestMatcher {
264+ readonly type = 'regex-url' ;
265+
266+ readonly regexSource : string ;
267+ readonly regexFlags : string ;
268+
269+ constructor ( regex : RegExp ) {
270+ super ( ) ;
271+ this . regexSource = regex . source ;
272+ this . regexFlags = regex . flags ;
273+ }
274+
275+ matches ( request : OngoingRequest ) {
276+ const absoluteUrl = normalizeUrl ( request . url ) ;
277+ const urlPath = getPathFromAbsoluteUrl ( absoluteUrl ) ;
278+
279+ // Test the matcher against both the path alone & the full URL
280+ const urlMatcher = new RegExp ( this . regexSource , this . regexFlags ) ;
281+ return urlMatcher . test ( absoluteUrl ) ;
282+ }
283+
284+ explain ( ) {
285+ return `matching /${ unescapeRegexp ( this . regexSource ) } /${ this . regexFlags ?? '' } ` ;
286+ }
287+
288+ }
289+
263290export class HeaderMatcher extends Serializable implements RequestMatcher {
264291 readonly type = 'header' ;
265292
@@ -590,6 +617,7 @@ export const MatcherLookup = {
590617 'port' : PortMatcher ,
591618 'simple-path' : SimplePathMatcher ,
592619 'regex-path' : RegexPathMatcher ,
620+ 'regex-url' : RegexUrlMatcher ,
593621 'header' : HeaderMatcher ,
594622 'query' : QueryMatcher ,
595623 'exact-query-string' : ExactQueryMatcher ,
0 commit comments