Skip to content

Commit 0f24183

Browse files
committed
[regex] fix uncaught exception when string is like "\\_"
fixes #129062
1 parent d65719f commit 0f24183

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

libcxx/include/regex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3955,7 +3955,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_character_escape(
39553955
++__first;
39563956
break;
39573957
default:
3958-
if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) {
3958+
if (!__traits_.isctype(*__first, ctype_base::alnum)) {
39593959
if (__str)
39603960
*__str = *__first;
39613961
else

libcxx/test/std/re/re.alg/re.alg.match/ecma.pass.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//===----------------------------------------------------------------------===//
88
//
99

10+
// XFAIL: FROZEN-CXX03-HEADERS-FIXME
11+
1012
// <regex>
1113

1214
// template <class BidirectionalIterator, class Allocator, class charT, class traits>
@@ -1305,6 +1307,21 @@ int main(int, char**)
13051307
assert(m.position(0) == 0);
13061308
assert(m.str(0) == s);
13071309
}
1310+
{
1311+
std::wcmatch m;
1312+
const wchar_t s[] = L"$_se";
1313+
assert(std::regex_match(s, m, std::wregex(L"\\$\\_se")));
1314+
assert(m.size() == 1);
1315+
assert(!m.prefix().matched);
1316+
assert(m.prefix().first == s);
1317+
assert(m.prefix().second == m[0].first);
1318+
assert(!m.suffix().matched);
1319+
assert(m.suffix().first == m[0].second);
1320+
assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
1321+
assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1322+
assert(m.position(0) == 0);
1323+
assert(m.str(0) == s);
1324+
}
13081325
#endif // TEST_HAS_NO_WIDE_CHARACTERS
13091326

13101327
return 0;

0 commit comments

Comments
 (0)