mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibRegex: Disallow duplicate named capture groups in ECMA262 parser
This commit is contained in:
parent
be3b806487
commit
733a70671b
Notes:
sideshowbarker
2024-07-17 22:31:10 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/733a70671b9 Pull-request: https://github.com/SerenityOS/serenity/pull/11316 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/linusg ✅
4 changed files with 11 additions and 0 deletions
|
@ -591,6 +591,8 @@ TEST_CASE(ECMA262_parse)
|
|||
{ "a{9007199254740991,9007199254740992}"sv, regex::Error::InvalidBraceContent },
|
||||
{ "a{9007199254740992,9007199254740991}"sv, regex::Error::InvalidBraceContent },
|
||||
{ "a{9007199254740992,9007199254740992}"sv, regex::Error::InvalidBraceContent },
|
||||
{ "(?<a>a)(?<a>b)"sv, regex::Error::DuplicateNamedCapture },
|
||||
{ "(?<a>a)(?<b>b)(?<a>c)"sv, regex::Error::DuplicateNamedCapture },
|
||||
};
|
||||
|
||||
for (auto& test : tests) {
|
||||
|
|
|
@ -38,6 +38,7 @@ enum __Regex_Error {
|
|||
__Regex_InvalidCaptureGroup, // Content of capture group is invalid.
|
||||
__Regex_InvalidNameForCaptureGroup, // Name of capture group is invalid.
|
||||
__Regex_InvalidNameForProperty, // Name of property is invalid.
|
||||
__Regex_DuplicateNamedCapture, // Duplicate named capture group
|
||||
};
|
||||
|
||||
enum ReError {
|
||||
|
|
|
@ -35,6 +35,7 @@ enum class Error : u8 {
|
|||
InvalidCaptureGroup = __Regex_InvalidCaptureGroup, // Content of capture group is invalid.
|
||||
InvalidNameForCaptureGroup = __Regex_InvalidNameForCaptureGroup, // Name of capture group is invalid.
|
||||
InvalidNameForProperty = __Regex_InvalidNameForProperty, // Name of property is invalid.
|
||||
DuplicateNamedCapture = __Regex_DuplicateNamedCapture, // Name of property is invalid.
|
||||
};
|
||||
|
||||
inline String get_error_string(Error error)
|
||||
|
@ -76,6 +77,8 @@ inline String get_error_string(Error error)
|
|||
return "Name of capture group is invalid.";
|
||||
case Error::InvalidNameForProperty:
|
||||
return "Name of property is invalid.";
|
||||
case Error::DuplicateNamedCapture:
|
||||
return "Duplicate capture group name";
|
||||
}
|
||||
return "Undefined error.";
|
||||
}
|
||||
|
|
|
@ -2166,6 +2166,11 @@ bool ECMA262Parser::parse_capture_group(ByteCode& stack, size_t& match_length_mi
|
|||
return false;
|
||||
}
|
||||
|
||||
if (m_parser_state.named_capture_groups.contains(name)) {
|
||||
set_error(Error::DuplicateNamedCapture);
|
||||
return false;
|
||||
}
|
||||
|
||||
ByteCode capture_group_bytecode;
|
||||
size_t length = 0;
|
||||
enter_capture_group_scope();
|
||||
|
|
Loading…
Reference in a new issue