Fix pattern escaping in regex used for \R so it works when the x-modifier is in effect.

Fixes: https://svn.boost.org/trac10/ticket/12960
This commit is contained in:
jzmaddock
2017-08-03 18:04:41 +01:00
parent 5c543a8e2b
commit a32e0cc9d3
2 changed files with 13 additions and 6 deletions

View File

@ -330,11 +330,11 @@ inline const charT* get_escape_R_string()
# pragma warning(push)
# pragma warning(disable:4309 4245)
#endif
static const charT e1[] = { '(', '?', '>', '\x0D', '\x0A', '?',
'|', '[', '\x0A', '\x0B', '\x0C', static_cast<unsigned char>('\x85'), '\\', 'x', '{', '2', '0', '2', '8', '}',
static const charT e1[] = { '(', '?', '>', '\\', 'x', '0', 'D', '\\', 'x', '0', 'A', '?',
'|', '[', '\\', 'x', '0', 'A', '\\', 'x', '0', 'B', '\\', 'x', '0', 'C', static_cast<unsigned char>('\x85'), '\\', 'x', '{', '2', '0', '2', '8', '}',
'\\', 'x', '{', '2', '0', '2', '9', '}', ']', ')', '\0' };
static const charT e2[] = { '(', '?', '>', '\x0D', '\x0A', '?',
'|', '[', '\x0A', '\x0B', '\x0C', static_cast<unsigned char>('\x85'), ']', ')', '\0' };
static const charT e2[] = { '(', '?', '>', '\\', 'x', '0', 'D', '\\', 'x', '0', 'A', '?',
'|', '[', '\\', 'x', '0', 'A', '\\', 'x', '0', 'B', '\\', 'x', '0', 'C', static_cast<unsigned char>('\x85'), ']', ')', '\0' };
charT c = static_cast<charT>(0x2029u);
bool b = (static_cast<unsigned>(c) == 0x2029u);
@ -352,8 +352,8 @@ inline const char* get_escape_R_string<char>()
# pragma warning(push)
# pragma warning(disable:4309)
#endif
static const char e2[] = { '(', '?', '>', '\x0D', '\x0A', '?',
'|', '[', '\x0A', '\x0B', '\x0C', '\x85', ']', ')', '\0' };
static const char e2[] = { '(', '?', '>', '\\', 'x', '0', 'D', '\\', 'x', '0', 'A', '?',
'|', '[', '\\', 'x', '0', 'A', '\\', 'x', '0', 'B', '\\', 'x', '0', 'C', '\\', 'x', '8', '5', ']', ')', '\0' };
return e2;
#ifdef BOOST_MSVC
# pragma warning(pop)

View File

@ -155,12 +155,19 @@ void test_assertion_escapes()
TEST_REGEX_SEARCH("\\R", perl, "foo\nbar", match_default, make_array(3, 4, -2, -2));
TEST_REGEX_SEARCH("\\R", perl, "foo\rbar", match_default, make_array(3, 4, -2, -2));
TEST_REGEX_SEARCH("\\R", perl, "foo\r\nbar", match_default, make_array(3, 5, -2, -2));
TEST_REGEX_SEARCH("(?x) abc \\R", perl, "abc\r\nbar", match_default, make_array(0, 5, -2, -2));
TEST_REGEX_SEARCH("(?x) abc \\R", perl, "abc\x0A" "bar", match_default, make_array(0, 4, -2, -2));
TEST_REGEX_SEARCH("(?x) abc \\R", perl, "abc\x0B" "bar", match_default, make_array(0, 4, -2, -2));
TEST_REGEX_SEARCH("(?x) abc \\R", perl, "abc\x0C" "bar", match_default, make_array(0, 4, -2, -2));
TEST_REGEX_SEARCH("(?x) abc \\R", perl, "abc\x85" "bar", match_default, make_array(0, 4, -2, -2));
// see if \u works:
const wchar_t* w = L"\u2028";
if(*w == 0x2028u)
{
TEST_REGEX_SEARCH_W(L"\\R", perl, L"foo\u2028bar", match_default, make_array(3, 4, -2, -2));
TEST_REGEX_SEARCH_W(L"\\R", perl, L"foo\u2029bar", match_default, make_array(3, 4, -2, -2));
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));
}
}