[libcxx-commits] [libcxx] [regex] fix uncaught exception when string is like "\\_" (PR #129348)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Mar 7 23:20:12 PST 2025
https://github.com/Zhenhang1213 updated https://github.com/llvm/llvm-project/pull/129348
>From 3c29eb9d41133c628f9f8f9313c397e8438e93dd Mon Sep 17 00:00:00 2001
From: Austin <zhenhangwang at huawei.com>
Date: Sat, 1 Mar 2025 10:37:20 +0800
Subject: [PATCH] [regex] fix uncaught exception when string is like "\\_"
fixes #129062
---
libcxx/include/regex | 2 +-
.../std/re/re.alg/re.alg.match/ecma.pass.cpp | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/libcxx/include/regex b/libcxx/include/regex
index 36ea55ce30921..6916f91628821 100644
--- a/libcxx/include/regex
+++ b/libcxx/include/regex
@@ -3954,7 +3954,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_character_escape(
++__first;
break;
default:
- if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) {
+ if (!__traits_.isctype(*__first, ctype_base::alnum)) {
if (__str)
*__str = *__first;
else
diff --git a/libcxx/test/std/re/re.alg/re.alg.match/ecma.pass.cpp b/libcxx/test/std/re/re.alg/re.alg.match/ecma.pass.cpp
index 4face8ba02bbe..559a2db20ae1a 100644
--- a/libcxx/test/std/re/re.alg/re.alg.match/ecma.pass.cpp
+++ b/libcxx/test/std/re/re.alg/re.alg.match/ecma.pass.cpp
@@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
//
+// XFAIL: FROZEN-CXX03-HEADERS-FIXME
+
// <regex>
// template <class BidirectionalIterator, class Allocator, class charT, class traits>
@@ -669,6 +671,21 @@ int main(int, char**)
assert(m.position(0) == 0);
assert(m.str(0) == s);
}
+ {
+ std::cmatch m;
+ const char s[] = "$_se";
+ assert(std::regex_match(s, m, std::regex("\\$\\_se")));
+ assert(m.size() == 1);
+ assert(!m.prefix().matched);
+ assert(m.prefix().first == s);
+ assert(m.prefix().second == m[0].first);
+ assert(!m.suffix().matched);
+ assert(m.suffix().first == m[0].second);
+ assert(m.suffix().second == s + std::char_traits<char>::length(s));
+ assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
+ assert(m.position(0) == 0);
+ assert(m.str(0) == s);
+ }
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
{
More information about the libcxx-commits
mailing list