Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/rules/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,19 +465,21 @@ export class RawBodyIncludesMatcher extends Serializable implements RequestMatch
export class RegexBodyMatcher extends Serializable implements RequestMatcher {
readonly type = 'raw-body-regexp';
readonly regexString: string;
readonly regexFlags: string;

constructor(regex: RegExp) {
super();
this.regexString = regex.source;
this.regexFlags = regex.flags;
}

async matches(request: OngoingRequest) {
let bodyMatcher = new RegExp(this.regexString);
let bodyMatcher = new RegExp(this.regexString, this.regexFlags);
return bodyMatcher.test(await request.body.asText());
}

explain() {
return `with a body matching /${unescapeRegexp(this.regexString)}/`;
return `with a body matching /${unescapeRegexp(this.regexString)}/${this.regexFlags ?? ''}`;
}

}
Expand Down
7 changes: 7 additions & 0 deletions test/integration/matchers/body-matching.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ describe("Body matching", function () {
method: 'POST'
})).not.to.have.responseText("matched");
});

it('should respect the regular expression flags', async () => {
return expect(fetch(server.url, {
method: 'POST',
body: '{"USERNAME": "TEST", "passwd": "test"}'
})).to.have.responseText('matched');
});
});

describe("for included strings", () => {
Expand Down
Loading