diff --git a/NEWS b/NEWS index 064273b..61b8aa2 100644 --- a/NEWS +++ b/NEWS @@ -43,6 +43,9 @@ GNU sed NEWS -*- outline -*- has been listed in the documentation as a failed experiment for at least 10 years. That command is now removed. + sed -i s/a/b/ - now evokes an error, rather than attempting to operate + on the file named ./- + ** Build-related "make dist" now builds .tar.xz files, rather than .tar.gz ones. diff --git a/sed/execute.c b/sed/execute.c index 4ddbf55..49cfb45 100644 --- a/sed/execute.c +++ b/sed/execute.c @@ -549,8 +549,11 @@ open_next_file(const char *name, struct input *input) { buffer.length = 0; - if (name[0] == '-' && name[1] == '\0' && !in_place_extension) + if (name[0] == '-' && name[1] == '\0') { + if (in_place_extension) + panic(_("couldn't edit %s: is a terminal"), name); + clearerr(stdin); /* clear any stale EOF indication */ #if defined WIN32 || defined _WIN32 || defined __CYGWIN__ \ || defined MSDOS || defined __EMX__ diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index bc35add..bfffda0 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -7,6 +7,7 @@ SH_LOG_COMPILER = $(SHELL) # is listed in only one place. T = \ help-version.sh \ + in-place-hyphen.sh \ invalid-mb-seq-UMR.sh \ range-overlap.sh \ temp-file-cleanup.sh diff --git a/testsuite/in-place-hyphen.sh b/testsuite/in-place-hyphen.sh new file mode 100755 index 0000000..0e0eeda --- /dev/null +++ b/testsuite/in-place-hyphen.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# Verify that "-" is no longer treated as a file name with --in-place. + +# Copyright (C) 2015 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 . +. "${srcdir=.}/init.sh"; path_prepend_ ../sed +print_ver_ sed + +echo "sed: couldn't edit -: is a terminal" > exp-err || framework_failure_ + +fail=0 +sed -i 's/a/b/' - > out 2> err && fail=1 + +compare /dev/null out || fail=1 +compare exp-err err || fail=1 + +Exit $fail