From 905f884d5e2b70d226ac46317951db74653fcab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= Date: Sat, 28 Feb 2026 14:57:03 +0100 Subject: [PATCH] ``: Add test coverage for capture group reset between match attempts in `regex_search()` --- tests/std/tests/VSO_0000000_regex_use/test.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/std/tests/VSO_0000000_regex_use/test.cpp b/tests/std/tests/VSO_0000000_regex_use/test.cpp index f50db71aefc..af5a1e01ee0 100644 --- a/tests/std/tests/VSO_0000000_regex_use/test.cpp +++ b/tests/std/tests/VSO_0000000_regex_use/test.cpp @@ -2441,6 +2441,20 @@ void test_gh_6022() { g_regexTester.should_match("abaaacaabaaaadab", R"((?:(a*)b(\1*)a*c)+aabaaaad\2b)"); } +void test_gh_6118() { + // GH-6118: regex_search() sometimes incorrectly matches capturing groups + // regex_search() failed to reset capture groups between match attempts. + { + test_regex re_matching_inbetween(&g_regexTester, "a|(b)c"); + re_matching_inbetween.should_search_match_capture_groups("ba", "a", match_default, {{-1, -1}}); + } + + { + test_regex re_matching_at_end(&g_regexTester, "$|(b)c"); + re_matching_at_end.should_search_match_capture_groups("b", "", match_default, {{-1, -1}}); + } +} + int main() { test_dev10_449367_case_insensitivity_should_work(); test_dev11_462743_regex_collate_should_not_disable_regex_icase(); @@ -2503,6 +2517,7 @@ int main() { test_gh_5939(); test_gh_5944(); test_gh_6022(); + test_gh_6118(); return g_regexTester.result(); }