summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Altmanninger <aclopte@gmail.com>2024-11-03 14:06:48 +0100
committerMaxime Coste <mawww@kakoune.org>2024-11-04 07:15:34 +1100
commit6b9291104b72b678964024d35c3da5f34f86b2cb (patch)
treeeee785e7ffee50f17e2fa74c1c196e12a68ec9cc /src
parent60fcc3443ef199f329a4e5c4fcd94ad017813a9b (diff)
Fix backward regex search ending in DOTALL
I noticed that reverse searches ending in "." stopped working in version 2024.05.08: kak -n -e "exec %{%cfoobar<ret><esc>gj<a-/>foo.<ret>}' Bisects ca7471c25 (Compute StartDesc with an offset to effective start, 2024-03-18) which updated the find_next_start() logic for the forward case but not for backward case. Add a symmetrical change and test case, that seems to fix it. Not 100% sure if this is correct but feels so.
Diffstat (limited to 'src')
-rw-r--r--src/regex_impl.cc11
-rw-r--r--src/regex_impl.hh2
2 files changed, 12 insertions, 1 deletions
diff --git a/src/regex_impl.cc b/src/regex_impl.cc
index 4b404cfa..d86637cd 100644
--- a/src/regex_impl.cc
+++ b/src/regex_impl.cc
@@ -1594,6 +1594,17 @@ auto test_regex = UnitTest{[]{
}
{
+ TestVM<RegexMode::Backward | RegexMode::Search> vm{"oo(.{3,4}|f)"};
+ kak_assert(vm.backward_start_desc and vm.backward_start_desc->offset == 4);
+ for (int c = 0; c < CompiledRegex::StartDesc::count; ++c)
+ kak_assert(vm.backward_start_desc->map[c] == (c == 'f' or c == 'o'));
+
+ kak_assert(vm.exec("ooxxx", RegexExecFlags::None));
+ kak_assert(vm.exec("oofx", RegexExecFlags::None));
+ kak_assert(not vm.exec("oox😄", RegexExecFlags::None));
+ }
+
+ {
auto eq = [](const CompiledRegex::NamedCapture& lhs,
const CompiledRegex::NamedCapture& rhs) {
return lhs.name == rhs.name and
diff --git a/src/regex_impl.hh b/src/regex_impl.hh
index 7f3eb495..f62c31da 100644
--- a/src/regex_impl.hh
+++ b/src/regex_impl.hh
@@ -552,7 +552,7 @@ private:
{
auto prev = utf8::previous(pos, config.end);
if (start_desc.map[static_cast<unsigned char>(*prev)])
- return pos;
+ return utf8::advance(pos, start, CharCount(start_desc.offset));
pos = prev;
}
}