From 231dbc3ebfc253316ac2ed1d2e175cac0404dfc2 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Sat, 21 Jul 2018 15:19:41 +0100 Subject: [PATCH] Correct behaviour of \b when matching null-strings. See https://github.com/boostorg/regex/issues/40 --- .../boost/regex/v4/perl_matcher_common.hpp | 6 +++-- test/regress/test_escapes.cpp | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/include/boost/regex/v4/perl_matcher_common.hpp b/include/boost/regex/v4/perl_matcher_common.hpp index a0973da9..94cb14e6 100644 --- a/include/boost/regex/v4/perl_matcher_common.hpp +++ b/include/boost/regex/v4/perl_matcher_common.hpp @@ -476,12 +476,14 @@ bool perl_matcher::match_word_boundary() } else { - b = (m_match_flags & match_not_eow) ? true : false; + if (m_match_flags & match_not_eow) + return false; + b = false; } if((position == backstop) && ((m_match_flags & match_prev_avail) == 0)) { if(m_match_flags & match_not_bow) - b ^= true; + return false; else b ^= false; } diff --git a/test/regress/test_escapes.cpp b/test/regress/test_escapes.cpp index 2511fcfe..afefc97a 100644 --- a/test/regress/test_escapes.cpp +++ b/test/regress/test_escapes.cpp @@ -169,5 +169,30 @@ void test_assertion_escapes() TEST_REGEX_SEARCH_W(L"(?x) abc \\R", perl, L"abc\u2028bar", match_default, make_array(0, 4, -2, -2)); TEST_REGEX_SEARCH_W(L"(?x) abc \\R", perl, L"abc\u2029bar", match_default, make_array(0, 4, -2, -2)); } + // Bug report: https://github.com/boostorg/regex/issues/40 + TEST_REGEX_SEARCH("\\b", perl, "", match_default, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\b", perl, "", match_not_bow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\b", perl, "", match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\b", perl, "", match_not_bow | match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\b", perl, "-", match_default, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\b", perl, "-", match_not_bow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\b", perl, "-", match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\b", perl, "-", match_not_bow | match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\<", perl, "", match_default, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\<", perl, "", match_not_bow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\<", perl, "", match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\<", perl, "", match_not_bow | match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\<", perl, "-", match_default, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\<", perl, "-", match_not_bow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\<", perl, "-", match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\<", perl, "-", match_not_bow | match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\>", perl, "", match_default, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\>", perl, "", match_not_bow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\>", perl, "", match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\>", perl, "", match_not_bow | match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\>", perl, "-", match_default, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\>", perl, "-", match_not_bow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\>", perl, "-", match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\>", perl, "-", match_not_bow | match_not_eow, make_array(-2, -2)); }