summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2022-01-21 20:08:47 +0330
committerLinus Groh <mail@linusgroh.de>2022-01-22 00:35:49 +0000
commit97dde091702fac122ff2f5178e3773f170758f1b (patch)
tree46394fbab43892cfe0cbd7620a4a81fa3a150fb9 /Userland
parent704e0654b3e0c914d7b3c74b7a4b29a33223e767 (diff)
downloadserenity-97dde091702fac122ff2f5178e3773f170758f1b.zip
LibRegex: Allow ClearCaptureGroup to create new groups
Instead of leaking all capture groups and selectively clearing some, simply avoid leaking things and only "define" the ones that need to exist. This *actually* implements the capture groups ECMA262 quirk. Also adds the test removed in the previous commit (to avoid messing up test runs across bisects).
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibRegex/RegexByteCode.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/Userland/Libraries/LibRegex/RegexByteCode.cpp b/Userland/Libraries/LibRegex/RegexByteCode.cpp
index 6177a1f3e2..050f067ae0 100644
--- a/Userland/Libraries/LibRegex/RegexByteCode.cpp
+++ b/Userland/Libraries/LibRegex/RegexByteCode.cpp
@@ -329,8 +329,11 @@ ALWAYS_INLINE ExecutionResult OpCode_ClearCaptureGroup::execute(MatchInput const
{
if (input.match_index < state.capture_group_matches.size()) {
auto& group = state.capture_group_matches[input.match_index];
- if (id() < group.size())
- group[id()].reset();
+ auto group_id = id();
+ if (group_id >= group.size())
+ group.resize(group_id + 1);
+
+ group[group_id].reset();
}
return ExecutionResult::Continue;
}