Skip to content

Commit 04c5320

Browse files
committed
Correctly use regex flags in regex path matching
1 parent a1d9231 commit 04c5320

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/rules/matchers.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -234,25 +234,28 @@ export class SimplePathMatcher extends Serializable implements RequestMatcher {
234234

235235
export class RegexPathMatcher extends Serializable implements RequestMatcher {
236236
readonly type = 'regex-path';
237+
237238
readonly regexSource: string;
239+
readonly regexFlags: string;
238240

239241
constructor(regex: RegExp) {
240242
super();
241243
this.regexSource = regex.source;
244+
this.regexFlags = regex.flags;
242245
}
243246

244247
matches(request: OngoingRequest) {
245248
const absoluteUrl = normalizeUrl(request.url);
246249
const urlPath = getPathFromAbsoluteUrl(absoluteUrl);
247250

248251
// Test the matcher against both the path alone & the full URL
249-
const urlMatcher = new RegExp(this.regexSource);
252+
const urlMatcher = new RegExp(this.regexSource, this.regexFlags);
250253
return urlMatcher.test(absoluteUrl) ||
251254
urlMatcher.test(urlPath);
252255
}
253256

254257
explain() {
255-
return `matching /${unescapeRegexp(this.regexSource)}/`;
258+
return `matching /${unescapeRegexp(this.regexSource)}/${this.regexFlags ?? ''}`;
256259
}
257260

258261
}

0 commit comments

Comments
 (0)