mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 08:28:11 +00:00
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.
This commit is contained in:
parent
431782bcd6
commit
d85b9fd5a0
3 changed files with 49 additions and 4 deletions
|
@ -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("/(?:)/");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue