diff --git a/src/rules/matchers.ts b/src/rules/matchers.ts index 8d840ef01..3a125b406 100644 --- a/src/rules/matchers.ts +++ b/src/rules/matchers.ts @@ -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 ?? ''}`; } } diff --git a/test/integration/matchers/body-matching.spec.ts b/test/integration/matchers/body-matching.spec.ts index ed1160e91..20bbdb2d1 100644 --- a/test/integration/matchers/body-matching.spec.ts +++ b/test/integration/matchers/body-matching.spec.ts @@ -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", () => {