diff --git a/NEWS b/NEWS index 599735e..a7ecfa7 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,12 @@ GNU sed NEWS -*- outline -*- * Noteworthy changes in release ?.? (????-??-??) [?] +** Bug fixes + + sed --posix no longer warns about escaped special characters in the + 's' command. + [bug introduced in sed 4.10] + * Noteworthy changes in release 4.10 (2026-04-21) [stable] diff --git a/THANKS.in b/THANKS.in index 4464b61..5615ed0 100644 --- a/THANKS.in +++ b/THANKS.in @@ -38,6 +38,7 @@ Jakub Jelinek jakub@redhat.com Jason Molenda crash@cygnus.com Karl Berry karl@freefriends.org Karl Heuer kwzh@gnu.org +Karl Ove Hufthammer karl@huftis.org Kaveh R. Ghazi ghazi@caip.rutgers.edu Kevin Buettner kev@cujo.geg.mot.com Laurent Vogel lvl@club-internet.fr diff --git a/sed/compile.c b/sed/compile.c index a55b1f6..f11b88f 100644 --- a/sed/compile.c +++ b/sed/compile.c @@ -486,8 +486,15 @@ match_slash (int slash, bool regex, bool s_command) /* Skip end-of-loop add1_buffer, we already did it. */ continue; } + /* Warn for some non-portable backslash escapes if --posix is + in use. Note that we ignore any special characters, although + they may be non-portable in some contexts. */ + char const *special_chars + = ((extended_regexp_flags & REG_EXTENDED) + ? ".[\\()*+?{}|^$" : ".[\\*^$)({}"); if (s_command && posixicity != POSIXLY_EXTENDED && ch != '&' - && ch != '\\' && !ISDIGIT (ch) && ch != '\n' && ch != slash) + && ch != '\\' && !ISDIGIT (ch) && ch != '\n' && ch != slash + && !strchr (special_chars, ch)) fprintf (stderr, _("%s: warning: using \"\\%c\" in the 's' " "command is not portable\n"), program_name, ch); diff --git a/testsuite/posix-backslash-warn.sh b/testsuite/posix-backslash-warn.sh index 73e46c8..6094069 100644 --- a/testsuite/posix-backslash-warn.sh +++ b/testsuite/posix-backslash-warn.sh @@ -90,4 +90,35 @@ sed --posix 's/abc/\|/g' input6 > out6 2> out-err6 || fail=1 compare_ out6 exp-out6 || fail=1 compare_ out-err6 exp-err6 || fail=1 +# Test that BRE interval expressions do not warn. +echo 'abc' > input7 || framework_failure_ +cat << \EOF > exp-out7 || framework_failure_ +def +EOF + +sed --posix 's/abc\{0,1\}/def/g' input7 > out7 2> out-err7 || fail=1 +compare_ out7 exp-out7 || fail=1 +compare_ out-err7 /dev/null || fail=1 + +# Test that BRE subexpressions do not warn. +echo 'abc' > input8 || framework_failure_ +cat << \EOF > exp-out8 || framework_failure_ +def +EOF + +sed --posix 's/ab\(c\)/def/g' input8 > out8 2> out-err8 || fail=1 +compare_ out8 exp-out8 || fail=1 +compare_ out-err8 /dev/null || fail=1 + +# Test that ERE special characters do not warn. +echo '.[\()*+?{}|^$' > input9 +cat << \EOF > exp-out9 || framework_failure_ +abc +EOF + +sed -E --posix 's/^\.\[\\\(\)\*\+\?\{\}\|\^\$$/abc/g' \ + input9 > out9 2> out-err9 || fail=1 +compare_ out9 exp-out9 || fail=1 +compare_ out-err9 /dev/null || fail=1 + Exit $fail