Skip to content

Commit 3c29eb9

Browse files
committed
[regex] fix uncaught exception when string is like "\\_"
fixes #129062
1 parent a955426 commit 3c29eb9

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
@@ -3954,7 +3954,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_character_escape(
39543954
++__first;
39553955
break;
39563956
default:
3957-
if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) {
3957+
if (!__traits_.isctype(*__first, ctype_base::alnum)) {
39583958
if (__str)
39593959
*__str = *__first;
39603960
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>
@@ -669,6 +671,21 @@ int main(int, char**)
669671
assert(m.position(0) == 0);
670672
assert(m.str(0) == s);
671673
}
674+
{
675+
std::cmatch m;
676+
const char s[] = "$_se";
677+
assert(std::regex_match(s, m, std::regex("\\$\\_se")));
678+
assert(m.size() == 1);
679+
assert(!m.prefix().matched);
680+
assert(m.prefix().first == s);
681+
assert(m.prefix().second == m[0].first);
682+
assert(!m.suffix().matched);
683+
assert(m.suffix().first == m[0].second);
684+
assert(m.suffix().second == s + std::char_traits<char>::length(s));
685+
assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
686+
assert(m.position(0) == 0);
687+
assert(m.str(0) == s);
688+
}
672689

673690
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
674691
{

0 commit comments

Comments
 (0)