>From b263599c2e24d0ed75884b931c555c4c9210559b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?=
Date: Sun, 23 Sep 2018 19:35:24 -0700 Subject: [PATCH] echo: always process escapes when POSIXLY_CORRECT is set * src/echo.c (main): Always enable backslash processing if POSIXLY_CORRECT is set. * tests/misc/echo.sh: Add (the first) test for the echo command. * tests/local.mk: Reference the new test. * tests/misc/printf.sh: Update a stale comment. * doc/coreutils.texi (echo invocation). Mention that POSIXLY_CORRECT now always enables backslash processing. * NEWS: Mention the change in behavior. Fixes https://bugs.gnu.org/32703 Issue identified by Eric Blake. --- NEWS | 6 +++++ doc/coreutils.texi | 2 +- src/echo.c | 5 ++-- tests/local.mk | 1 + tests/misc/echo.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/misc/printf.sh | 5 ++-- 6 files changed, 79 insertions(+), 6 deletions(-) create mode 100755 tests/misc/echo.sh diff --git a/NEWS b/NEWS index aa3b4f9..c826dc0 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,12 @@ GNU coreutils NEWS -*- outline -*- ** Bug fixes df no longer corrupts displayed multibyte characters on macOS. + [bug introduced with coreutils-8.18] + +** Changes in behavior + + echo now always processes backslash escapes when the POSIXLY_CORRECT + environment variable is set. * Noteworthy changes in release 8.30 (2018-07-01) [stable] diff --git a/doc/coreutils.texi b/doc/coreutils.texi index dc28996..c4f6473 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -12587,7 +12587,7 @@ If the @env{POSIXLY_CORRECT} environment variable is set, then when @command{echo}'s first argument is not @option{-n} it outputs option-like arguments instead of treating them as options. For example, @code{echo -ne hello} outputs @samp{-ne hello} instead of -plain @samp{hello}. +plain @samp{hello}. Also backslash escapes are always enabled. POSIX does not require support for any options, and says that the behavior of @command{echo} is implementation-defined if any diff --git a/src/echo.c b/src/echo.c index 9958a8e..2aee5ac 100644 --- a/src/echo.c +++ b/src/echo.c @@ -108,8 +108,9 @@ int main (int argc, char **argv) { bool display_return = true; + bool posixly_correct = getenv ("POSIXLY_CORRECT"); bool allow_options = - (! getenv ("POSIXLY_CORRECT") + (! posixly_correct || (! DEFAULT_ECHO_TO_XPG && 1 < argc && STREQ (argv[1], "-n"))); /* System V machines already have a /bin/sh with a v9 behavior. @@ -189,7 +190,7 @@ main (int argc, char **argv) just_echo: - if (do_v9) + if (do_v9 || posixly_correct) { while (argc > 0) { diff --git a/tests/local.mk b/tests/local.mk index 47c6b95..9b7cb74 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -237,6 +237,7 @@ all_tests = \ tests/fmt/base.pl \ tests/fmt/long-line.sh \ tests/fmt/goal-option.sh \ + tests/misc/echo.sh \ tests/misc/env.sh \ tests/misc/ptx.pl \ tests/misc/test.pl \ diff --git a/tests/misc/echo.sh b/tests/misc/echo.sh new file mode 100755 index 0000000..133b52a --- /dev/null +++ b/tests/misc/echo.sh @@ -0,0 +1,66 @@ +#!/bin/sh +# basic tests for echo + +# Copyright (C) 2018 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see