Skip to content

Commit 62128c2

Browse files
committed
Add a couple of last nitpick tweaks to withUrlMatching before merge
1 parent b223e94 commit 62128c2

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/rules/base-rule-builder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
HostnameMatcher,
3232
PortMatcher,
3333
ProtocolMatcher,
34-
RegexUrlMatcher,
34+
RegexUrlMatcher
3535
} from "./matchers";
3636

3737
/**
@@ -237,7 +237,7 @@ export abstract class BaseRuleBuilder {
237237
}
238238

239239
/**
240-
* Match only requests that sent with the given protocol.
240+
* Match only requests sent with the given protocol.
241241
* @category Matching
242242
*/
243243
withProtocol(protocol: "http" | "https" | "ws" | "wss"): this {
@@ -246,7 +246,7 @@ export abstract class BaseRuleBuilder {
246246
}
247247

248248
/**
249-
* Match only requests that has absolute url matching the given RegExp.
249+
* Match only requests whose absolute url matches the given RegExp.
250250
* @category Matching
251251
*/
252252
withUrlMatching(pattern: RegExp): this {

src/rules/matchers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,14 @@ export class RegexUrlMatcher extends Serializable implements RequestMatcher {
274274

275275
matches(request: OngoingRequest) {
276276
const absoluteUrl = normalizeUrl(request.url);
277-
const urlPath = getPathFromAbsoluteUrl(absoluteUrl);
278277

279278
// Test the matcher against the full URL
280279
const urlMatcher = new RegExp(this.regexSource, this.regexFlags);
281280
return urlMatcher.test(absoluteUrl);
282281
}
283282

284283
explain() {
285-
return `matching /${unescapeRegexp(this.regexSource)}/${this.regexFlags ?? ''}`;
284+
return `matching URL /${unescapeRegexp(this.regexSource)}/${this.regexFlags ?? ''}`;
286285
}
287286

288287
}

test/integration/matchers/method-path-matching.spec.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,24 @@ responses by hand.`);
128128
await expect(result).to.have.responseText('Fake file');
129129
});
130130

131-
it("should regex match requests for a matching URL with negative regexp -- pass", async () => {
131+
it("should not negative-regex match requests by full URL with forX matchers", async () => {
132+
// It's not so much that this is desired behaviour - more that it follows from the
133+
// definition of forGet matching, and we want to preserve it for now, as opposed
134+
// to usage of withUrlMatching (below) which does _not_ behave like this.
135+
132136
await server.forGet(/^(?!.*localhost)/).thenReply(200, 'Fake file');
133-
137+
134138
let result = await fetch(server.urlFor('/matching-file.txt'));
135139

136-
await expect(result).to.have.responseText('Fake file');
140+
await expect(result).to.have.responseText('Fake file');
137141
});
138142

139-
it("should regex match requests for a matching URL with negative regexp -- catch", async () => {
143+
it("should negative-regex match requests by full URL with withUrlMatching", async () => {
140144
await server.forGet().withUrlMatching(/^(?!.*localhost)/).thenReply(200, 'Fake file');
141-
145+
142146
let result2 = await fetch(server.urlFor('/matching-file.txt'));
143147

144-
await expect(result2).to.have.responseText(/^.*No rules*./);
148+
await expect(result2).to.have.responseText(/^.*No rules*./);
145149
});
146150

147151
it("should reject requests for the wrong path", async () => {
@@ -159,7 +163,6 @@ responses by hand.`);
159163

160164
expect(result.status).to.equal(503);
161165
});
162-
163166

164167
it("should match requests ignoring the query string", async () => {
165168
await server.forGet('/path').thenReply(200, 'Matched path');

0 commit comments

Comments
 (0)