Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<regex>: Correct characters not matched by special character dot #5192

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions stl/inc/regex
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ enum _Meta_type : int { // meta character representations for parser
_Meta_nl = '\n',
_Meta_cr = '\r',
_Meta_bsp = '\b',
_Meta_ls = L'\u2028',
_Meta_ps = L'\u2029',
_Meta_chr = 0,

_Esc_bsl = '\\',
Expand Down Expand Up @@ -3507,10 +3509,22 @@ bool _Matcher<_BidIt, _Elem, _RxTraits, _It>::_Match_pat(_Node_base* _Nx) { // c
break;

case _N_dot:
if (_Tgt_state._Cur == _End || *_Tgt_state._Cur == _Meta_nl || *_Tgt_state._Cur == _Meta_cr) {
if (_Tgt_state._Cur == _End) {
_Failed = true;
} else {
++_Tgt_state._Cur;
const _Elem _Ch = *_Tgt_state._Cur;
if (_Sflags
& (regex_constants::basic | regex_constants::extended | regex_constants::grep
| regex_constants::egrep | regex_constants::awk)) {
if (_Ch == _Elem()) {
_Failed = true;
}
} else if (_Ch == _Meta_nl || _Ch == _Meta_cr || _Ch == _Meta_ls || _Ch == _Meta_ps) { // ECMAScript
_Failed = true;
}
if (!_Failed) {
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
++_Tgt_state._Cur;
}
}

break;
Expand Down
38 changes: 38 additions & 0 deletions tests/std/tests/VSO_0000000_regex_use/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,43 @@ void test_gh_5160() {
neg_regex.should_search_fail(L"xxxYxx\x2009xxxZxxx"); // U+2009 THIN SPACE
}

void test_gh_5192() {
// GH-5192: Correct characters not matched by special character dot
using namespace string_literals;
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
for (const syntax_option_type option : {
regex_constants::basic,
regex_constants::extended,
regex_constants::awk,
regex_constants::grep,
regex_constants::egrep,
}) {
const test_regex regex(&g_regexTester, "^.*", option);
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
regex.should_search_match("abc\nd\re\0f"s, "abc\nd\re"s);
regex.should_search_match("abcd\re\ngh\0i"s, "abcd\re\ngh"s);

const test_wregex wregex(&g_regexTester, L"^.*", option);
wregex.should_search_match(L"abc\nd\re\0f"s, L"abc\nd\re"s);
wregex.should_search_match(L"abcd\re\ngh\0i"s, L"abcd\re\ngh"s);
wregex.should_search_match(L"abc\u2028d\ne\0f"s, L"abc\u2028d\ne"s); // U+2028 LINE SEPARATOR
wregex.should_search_match(L"abc\u2029d\ne\0f"s, L"abc\u2029d\ne"s); // U+2029 PARAGRAPH SEPARATOR
}

for (const syntax_option_type option : {
regex_constants::ECMAScript,
syntax_option_type(),
}) {
const test_regex regex(&g_regexTester, "^.*", option);
regex.should_search_match("ab\0c\nd\re\0f"s, "ab\0c"s);
regex.should_search_match("ab\0cd\re\ngh\0i"s, "ab\0cd"s);

const test_wregex wregex(&g_regexTester, L"^.*", option);
wregex.should_search_match(L"abc\0\nd\re\0f"s, L"abc\0"s);
wregex.should_search_match(L"ab\0cd\re\ngh\0i"s, L"ab\0cd"s);
wregex.should_search_match(L"ab\0c\u2028d\ne\0f"s, L"ab\0c"s); // U+2028 LINE SEPARATOR
wregex.should_search_match(L"a\0bc\u2029d\ne\0f"s, L"a\0bc"s); // U+2029 PARAGRAPH SEPARATOR
}
}

int main() {
test_dev10_449367_case_insensitivity_should_work();
test_dev11_462743_regex_collate_should_not_disable_regex_icase();
Expand Down Expand Up @@ -699,6 +736,7 @@ int main() {
test_gh_4995();
test_gh_5058();
test_gh_5160();
test_gh_5192();

return g_regexTester.result();
}
17 changes: 6 additions & 11 deletions tests/tr1/tests/regex3/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,12 @@ static void test_uncoveredgrammar() {
STDString str2(T("Prime number"));
STDString str3(T("aaaqxzbbb"));
STDString str4(T("aaa\nxzbbb"));
static const STD regex_constants::syntax_option_type flag[6] = {
STD regex_constants::ECMAScript,
STD regex_constants::basic,
STD regex_constants::extended,
STD regex_constants::awk,
STD regex_constants::grep,
STD regex_constants::egrep,
};
for (int i = 0; i <= 5; i++) {
rx1.assign(T(".*"), flag[i]);
rx2.assign(T("aaa...bbb"), flag[i]);
for (const STD regex_constants::syntax_option_type flag : {
STD regex_constants::ECMAScript,
STD regex_constants::syntax_option_type(),
}) {
rx1.assign(T(".*"), flag);
rx2.assign(T("aaa...bbb"), flag);
CHECK(!STD regex_match(str1, rx1));
CHECK(STD regex_match(str2, rx1));
CHECK(STD regex_match(str3, rx2));
Expand Down