diff options
author | Linus Groh <mail@linusgroh.de> | 2021-05-11 22:47:14 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-05-11 22:47:14 +0100 |
commit | d85b9fd5a09e451c5faa7922c3f8ab2661f0706e (patch) | |
tree | 3a3c02f492c1b0b3e92b316be2f556bb67543b0d /Userland/Libraries/LibJS/Tests | |
parent | 431782bcd6851fe8d4281a05d2115f180be86efa (diff) | |
download | serenity-d85b9fd5a09e451c5faa7922c3f8ab2661f0706e.zip |
LibJS: Bring back runtime validation of RegExp flags
This is a partial revert of commit 60064e2, which removed the validation
of RegExp flags during runtime and expected the parser to do that
exclusively - however this was not taking into account the RegExp()
constructor, which was subsequently crashing on invalid flags.
Also adds test for these constructor error cases, which were obviously
missing before.
Fixes #7042.
Diffstat (limited to 'Userland/Libraries/LibJS/Tests')
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/RegExp/RegExp.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/builtins/RegExp/RegExp.js b/Userland/Libraries/LibJS/Tests/builtins/RegExp/RegExp.js index 9ae8ab97c0..0a65d2a25b 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/RegExp/RegExp.js +++ b/Userland/Libraries/LibJS/Tests/builtins/RegExp/RegExp.js @@ -1,3 +1,26 @@ +describe("errors", () => { + test("invalid pattern", () => { + expect(() => { + RegExp("["); + }).toThrowWithMessage( + SyntaxError, + "RegExp compile error: Error during parsing of regular expression:" + ); + }); + + test("invalid flag", () => { + expect(() => { + RegExp("", "x"); + }).toThrowWithMessage(SyntaxError, "Invalid RegExp flag 'x'"); + }); + + test("repeated flag", () => { + expect(() => { + RegExp("", "gg"); + }).toThrowWithMessage(SyntaxError, "Repeated RegExp flag 'g'"); + }); +}); + test("basic functionality", () => { expect(RegExp().toString()).toBe("/(?:)/"); expect(RegExp(undefined).toString()).toBe("/(?:)/"); |