diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-07-24 12:55:04 +0430 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-07-24 20:52:43 +0430 |
commit | 1dd137815970555c34c49bdb3c2049819a178c7d (patch) | |
tree | 9141586524b10a9c0389de0056be24360d937e9c /Userland | |
parent | f36607dc95af002bd08d49007b1ec32121cba3ee (diff) | |
download | serenity-1dd137815970555c34c49bdb3c2049819a178c7d.zip |
LibRegex: Preserve the type of the match when clearing capture groups
Even though the contents are supposed to be reset, the type should stay
unchanged, as that's an assumption the engine is making.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibRegex/RegexByteCode.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibRegex/RegexMatch.h | 19 |
2 files changed, 22 insertions, 2 deletions
diff --git a/Userland/Libraries/LibRegex/RegexByteCode.cpp b/Userland/Libraries/LibRegex/RegexByteCode.cpp index f5869acbdb..964d403c68 100644 --- a/Userland/Libraries/LibRegex/RegexByteCode.cpp +++ b/Userland/Libraries/LibRegex/RegexByteCode.cpp @@ -299,7 +299,7 @@ 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()] = {}; + group[id()].reset(); } return ExecutionResult::Continue; } @@ -353,7 +353,8 @@ ALWAYS_INLINE ExecutionResult OpCode_ClearNamedCaptureGroup::execute(MatchInput { if (input.match_index < state.capture_group_matches.size()) { auto& group = state.named_capture_group_matches[input.match_index]; - group.remove(name()); + if (auto it = group.find(name()); it != group.end()) + it->value.reset(); } return ExecutionResult::Continue; } diff --git a/Userland/Libraries/LibRegex/RegexMatch.h b/Userland/Libraries/LibRegex/RegexMatch.h index 4ed5cab2f0..b6cd0e0793 100644 --- a/Userland/Libraries/LibRegex/RegexMatch.h +++ b/Userland/Libraries/LibRegex/RegexMatch.h @@ -101,6 +101,16 @@ public: [](auto const& view) { return view.length(); }); } + RegexStringView typed_null_view() + { + auto view = m_view.visit( + [&]<typename T>(T const&) { + return RegexStringView { T {} }; + }); + view.set_unicode(unicode()); + return view; + } + RegexStringView construct_as_same(Span<u32> data, Optional<String>& optional_string_storage, Vector<u16>& optional_utf16_storage) const { auto view = m_view.visit( @@ -417,6 +427,15 @@ public: { } + void reset() + { + view = view.typed_null_view(); + line = 0; + column = 0; + global_offset = 0; + left_column = 0; + } + RegexStringView view { nullptr }; size_t line { 0 }; size_t column { 0 }; |