From dc1a84e65b5fd4c4625a309fd11058d5c9eb2e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= Date: Fri, 28 Mar 2025 18:16:42 +0100 Subject: [PATCH 1/2] ``: Fix word bounds `\b` and `\B` when applied to the empty string --- stl/inc/regex | 2 +- tests/std/tests/VSO_0000000_regex_use/test.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/stl/inc/regex b/stl/inc/regex index 17fd2ee72c5..e372d6119f1 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -3497,7 +3497,7 @@ bool _Matcher<_BidIt, _Elem, _RxTraits, _It>::_Is_wbound() const { } } else { // --_Cur is not valid if (_Tgt_state._Cur == _End) { - return (_Mflags & (regex_constants::match_not_bow | regex_constants::match_not_eow)) == 0; + return false; } else { return (_Mflags & regex_constants::match_not_bow) == 0 && _Is_word(*_Tgt_state._Cur); } diff --git a/tests/std/tests/VSO_0000000_regex_use/test.cpp b/tests/std/tests/VSO_0000000_regex_use/test.cpp index ba9c575940a..7ef92d2f0fb 100644 --- a/tests/std/tests/VSO_0000000_regex_use/test.cpp +++ b/tests/std/tests/VSO_0000000_regex_use/test.cpp @@ -499,7 +499,7 @@ void test_VSO_225160_match_eol_flag() { void test_VSO_226914_word_boundaries() { const test_regex emptyAnchor(&g_regexTester, R"(\b)"); - emptyAnchor.should_search_match("", ""); + emptyAnchor.should_search_fail(""); emptyAnchor.should_search_fail("", match_not_bow); emptyAnchor.should_search_fail("", match_not_eow); emptyAnchor.should_search_fail("", match_not_bow | match_not_eow); @@ -1171,6 +1171,12 @@ void test_gh_5253() { g_regexTester.should_not_match("a", "()*"); } +void test_gh_5371() { + // GH-5371 : \b and \B are backwards on empty strings + g_regexTester.should_not_match("", "\\b"); + g_regexTester.should_match("", "\\B"); +} + int main() { test_dev10_449367_case_insensitivity_should_work(); test_dev11_462743_regex_collate_should_not_disable_regex_icase(); @@ -1208,6 +1214,7 @@ int main() { test_gh_5192(); test_gh_5214(); test_gh_5253(); + test_gh_5371(); return g_regexTester.result(); } From ca633208ce3370681c88192b38c32df898e76fec Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 1 Apr 2025 14:57:28 -0700 Subject: [PATCH 2/2] Use raw string literals. --- tests/std/tests/VSO_0000000_regex_use/test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/std/tests/VSO_0000000_regex_use/test.cpp b/tests/std/tests/VSO_0000000_regex_use/test.cpp index 7ef92d2f0fb..2f9d3fec28a 100644 --- a/tests/std/tests/VSO_0000000_regex_use/test.cpp +++ b/tests/std/tests/VSO_0000000_regex_use/test.cpp @@ -1173,8 +1173,8 @@ void test_gh_5253() { void test_gh_5371() { // GH-5371 : \b and \B are backwards on empty strings - g_regexTester.should_not_match("", "\\b"); - g_regexTester.should_match("", "\\B"); + g_regexTester.should_not_match("", R"(\b)"); + g_regexTester.should_match("", R"(\B)"); } int main() {