mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:37:35 +00:00
LibRegex: Allow dollar signs in ECMA262 named capture groups
Fixes 1 test262 test.
This commit is contained in:
parent
d3a2e492fb
commit
65003241e4
3 changed files with 25 additions and 1 deletions
|
@ -422,6 +422,27 @@ TEST_CASE(named_capture_group)
|
||||||
EXPECT_EQ(result.named_capture_group_matches.at(1).ensure("Test").view, "0");
|
EXPECT_EQ(result.named_capture_group_matches.at(1).ensure("Test").view, "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE(ecma262_named_capture_group_with_dollar_sign)
|
||||||
|
{
|
||||||
|
Regex<ECMA262> re("[a-zA-Z]*=(?<$Test$>[0-9]*)");
|
||||||
|
RegexResult result;
|
||||||
|
|
||||||
|
if constexpr (REGEX_DEBUG) {
|
||||||
|
RegexDebug regex_dbg(stderr);
|
||||||
|
regex_dbg.print_raw_bytecode(re);
|
||||||
|
regex_dbg.print_header();
|
||||||
|
regex_dbg.print_bytecode(re);
|
||||||
|
}
|
||||||
|
|
||||||
|
String haystack = "[Window]\nOpacity=255\nAudibleBeep=0\n";
|
||||||
|
EXPECT_EQ(re.search(haystack, result, ECMAScriptFlags::Multiline), true);
|
||||||
|
EXPECT_EQ(result.count, 2u);
|
||||||
|
EXPECT_EQ(result.matches.at(0).view, "Opacity=255");
|
||||||
|
EXPECT_EQ(result.named_capture_group_matches.at(0).ensure("$Test$").view, "255");
|
||||||
|
EXPECT_EQ(result.matches.at(1).view, "AudibleBeep=0");
|
||||||
|
EXPECT_EQ(result.named_capture_group_matches.at(1).ensure("$Test$").view, "0");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE(a_star)
|
TEST_CASE(a_star)
|
||||||
{
|
{
|
||||||
Regex<PosixExtended> re("a*");
|
Regex<PosixExtended> re("a*");
|
||||||
|
|
|
@ -138,6 +138,9 @@ test("replacement with substitution", () => {
|
||||||
expect("abc".replace(/(?<val1>a)b(?<val2>c)/, "$<val1>")).toBe("a");
|
expect("abc".replace(/(?<val1>a)b(?<val2>c)/, "$<val1>")).toBe("a");
|
||||||
expect("abc".replace(/(?<val1>a)b(?<val2>c)/, "$<val2>")).toBe("c");
|
expect("abc".replace(/(?<val1>a)b(?<val2>c)/, "$<val2>")).toBe("c");
|
||||||
expect("abc".replace(/(?<val1>a)b(?<val2>c)/, "$<val2>b$<val1>")).toBe("cba");
|
expect("abc".replace(/(?<val1>a)b(?<val2>c)/, "$<val2>b$<val1>")).toBe("cba");
|
||||||
|
|
||||||
|
expect(/(?<𝒜>b)/u[Symbol.replace]("abc", "d$<𝒜>$`")).toBe("adbac");
|
||||||
|
expect(/(?<$𐒤>b)/gu[Symbol.replace]("abc", "$'$<$𐒤>d")).toBe("acbdc");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("replacement with substitution and 'groups' coerced to an object", () => {
|
test("replacement with substitution and 'groups' coerced to an object", () => {
|
||||||
|
|
|
@ -1625,7 +1625,7 @@ StringView ECMA262Parser::read_capture_group_specifier(bool take_starting_angle_
|
||||||
|
|
||||||
auto start_token = m_parser_state.current_token;
|
auto start_token = m_parser_state.current_token;
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
while (match(TokenType::Char)) {
|
while (match(TokenType::Char) || match(TokenType::Dollar)) {
|
||||||
auto c = m_parser_state.current_token.value();
|
auto c = m_parser_state.current_token.value();
|
||||||
if (c == ">")
|
if (c == ">")
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue