summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Libraries/LibRegex/RegexParser.cpp5
-rw-r--r--Libraries/LibRegex/Tests/Regex.cpp1
2 files changed, 6 insertions, 0 deletions
diff --git a/Libraries/LibRegex/RegexParser.cpp b/Libraries/LibRegex/RegexParser.cpp
index 6015212123..2afbad64c7 100644
--- a/Libraries/LibRegex/RegexParser.cpp
+++ b/Libraries/LibRegex/RegexParser.cpp
@@ -741,6 +741,11 @@ bool ECMA262Parser::parse_assertion(ByteCode& stack, [[maybe_unused]] size_t& ma
if (!try_skip("(?"))
return false;
+ if (done()) {
+ set_error(Error::InvalidCaptureGroup);
+ return false;
+ }
+
ByteCode assertion_stack;
size_t length_dummy = 0;
diff --git a/Libraries/LibRegex/Tests/Regex.cpp b/Libraries/LibRegex/Tests/Regex.cpp
index e4fb05c3c4..0bb2e8d2ef 100644
--- a/Libraries/LibRegex/Tests/Regex.cpp
+++ b/Libraries/LibRegex/Tests/Regex.cpp
@@ -500,6 +500,7 @@ TEST_CASE(ECMA262_parse)
{ "(?", regex::Error::InvalidCaptureGroup },
{ "\\u1234", regex::Error::NoError, regex::ECMAScriptFlags::Unicode },
{ "[\\u1234]", regex::Error::NoError, regex::ECMAScriptFlags::Unicode },
+ { ",(?", regex::Error::InvalidCaptureGroup }, // #4583
};
for (auto& test : tests) {