Skip to content

Commit b69d5f5

Browse files
<regex>: Fix word bounds \b and \B when applied to the empty string (#5375)
Co-authored-by: Stephan T. Lavavej <[email protected]>
1 parent 6791615 commit b69d5f5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

stl/inc/regex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3521,7 +3521,7 @@ bool _Matcher<_BidIt, _Elem, _RxTraits, _It>::_Is_wbound() const {
35213521
}
35223522
} else { // --_Cur is not valid
35233523
if (_Tgt_state._Cur == _End) {
3524-
return (_Mflags & (regex_constants::match_not_bow | regex_constants::match_not_eow)) == 0;
3524+
return false;
35253525
} else {
35263526
return (_Mflags & regex_constants::match_not_bow) == 0 && _Is_word(*_Tgt_state._Cur);
35273527
}

tests/std/tests/VSO_0000000_regex_use/test.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ void test_VSO_225160_match_eol_flag() {
499499

500500
void test_VSO_226914_word_boundaries() {
501501
const test_regex emptyAnchor(&g_regexTester, R"(\b)");
502-
emptyAnchor.should_search_match("", "");
502+
emptyAnchor.should_search_fail("");
503503
emptyAnchor.should_search_fail("", match_not_bow);
504504
emptyAnchor.should_search_fail("", match_not_eow);
505505
emptyAnchor.should_search_fail("", match_not_bow | match_not_eow);
@@ -1434,6 +1434,12 @@ void test_gh_5364() {
14341434
g_regexTester.should_match("c", "[^]", ECMAScript);
14351435
}
14361436

1437+
void test_gh_5371() {
1438+
// GH-5371 <regex>: \b and \B are backwards on empty strings
1439+
g_regexTester.should_not_match("", R"(\b)");
1440+
g_regexTester.should_match("", R"(\B)");
1441+
}
1442+
14371443
int main() {
14381444
test_dev10_449367_case_insensitivity_should_work();
14391445
test_dev11_462743_regex_collate_should_not_disable_regex_icase();
@@ -1474,6 +1480,7 @@ int main() {
14741480
test_gh_5253();
14751481
test_gh_5362();
14761482
test_gh_5364();
1483+
test_gh_5371();
14771484

14781485
return g_regexTester.result();
14791486
}

0 commit comments

Comments
 (0)