Skip to content

Commit c5ed364

Browse files
authored
<regex>: Permit escaping of closing brackets in POSIX regexes (#5399)
1 parent 81056a9 commit c5ed364

File tree

2 files changed

+9
-5
lines changed
  • stl/inc
  • tests/std/tests/GH_005244_regex_escape_sequences

2 files changed

+9
-5
lines changed

stl/inc/regex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4403,6 +4403,7 @@ bool _Parser<_FwdIt, _Elem, _RxTraits>::_IsIdentityEscape(bool _In_character_cla
44034403
return true;
44044404
case _Meta_dot:
44054405
case _Meta_lsq:
4406+
case _Meta_rsq:
44064407
case _Meta_star:
44074408
case _Meta_caret:
44084409
case _Meta_dlr:

tests/std/tests/GH_005244_regex_escape_sequences/test.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,13 @@ void test_gh_5244_atomescape_posix_common(syntax_option_type option) {
470470
check_atomescape_identityescape("^", option);
471471
check_atomescape_identityescape("$", option);
472472

473+
// Even though [ is special, ] is not,
474+
// so the interpretation of the escape sequence \] is undefined
475+
// according to the POSIX standard referenced in the C++ standard.
476+
// But we treat \] as an identity escape in line with
477+
// more recent versions of the POSIX standard.
478+
check_atomescape_identityescape("]", option);
479+
473480
// Sections on "BRE Special Characters" and "ERE Special Characters":
474481
// escaping ordinary characters is undefined -> reject
475482
g_regexTester.should_throw(R"(\B)", error_escape, option);
@@ -483,9 +490,6 @@ void test_gh_5244_atomescape_posix_common(syntax_option_type option) {
483490
g_regexTester.should_throw(R"(\W)", error_escape, option);
484491
g_regexTester.should_throw(R"(\s)", error_escape, option);
485492
g_regexTester.should_throw(R"(\S)", error_escape, option);
486-
487-
// while [ is special, ] is not
488-
g_regexTester.should_throw(R"(\])", error_escape, option);
489493
}
490494

491495
void test_gh_5244_atomescape_posix_not_awk(syntax_option_type option) {
@@ -524,8 +528,6 @@ void test_gh_5244_atomescape_basic_or_grep(syntax_option_type option) {
524528
}
525529

526530
void test_gh_5244_atomescape_extended_egrep_awk(syntax_option_type option) {
527-
test_gh_5244_atomescape_posix_common(option);
528-
529531
// check that the parser accepts escaped characters
530532
// that are only special in extended regexes
531533
check_atomescape_identityescape("+", option);
@@ -557,6 +559,7 @@ void test_gh_5244_atomescape_extended_or_egrep(syntax_option_type option) {
557559

558560
void test_gh_5244_atomescape_awk() {
559561
test_gh_5244_atomescape_extended_egrep_awk(awk);
562+
test_gh_5244_atomescape_posix_common(awk);
560563

561564
// awk-only escapes
562565
check_atomescape_controlescape("\a", "a", awk);

0 commit comments

Comments
 (0)