@@ -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
491495void 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
526530void 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
558560void 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