Skip to content

Commit 294e290

Browse files
committed
fix: derive matches based on matchAll length
1 parent 956fed2 commit 294e290

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/core/utils/matching/matchRequestUrl.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@ it('returns false when a RegExp does not match', () => {
3535
params: {},
3636
},
3737
)
38+
39+
expect(
40+
matchRequestUrl(new URL('https://test.mswjs.io'), /foo\.bar/g),
41+
).toEqual({
42+
matches: false,
43+
params: {},
44+
})
45+
46+
expect(matchRequestUrl(new URL('https://test.mswjs.io'), /foo(.+)/)).toEqual({
47+
matches: false,
48+
params: {},
49+
})
50+
51+
expect(matchRequestUrl(new URL('https://test.mswjs.io'), /foo(.+)/g)).toEqual(
52+
{
53+
matches: false,
54+
params: {},
55+
},
56+
)
3857
})
3958

4059
it('ignores query parameters when matching against a RegExp', () => {

src/core/utils/matching/matchRequestUrl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function matchRequestUrl(
3232
: cleanUrl.match(pattern)
3333

3434
return {
35-
matches: match != null,
35+
matches: match != null && match.length > 0,
3636
params: Object.fromEntries(
3737
(match ?? []).slice(1).map((value, index) => [index, value]),
3838
),

0 commit comments

Comments
 (0)