]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
ls: consistently quote symlink targets
authorPádraig Brady <P@draigBrady.com>
Thu, 24 Aug 2017 07:18:41 +0000 (00:18 -0700)
committerPádraig Brady <P@draigBrady.com>
Fri, 25 Aug 2017 02:26:32 +0000 (19:26 -0700)
* src/ls.c (gobble_file): Disable the optimization to avoid quoting
if the symlink target itself needs quoting.  This was introduced
with the quoting alignment adjustments in v8.25-106-g01971c0
* tests/ls/symlink-quote.sh: Add a test.
* tests/local.mk: Reference the test.
* NEWS: Mention the fix.

NEWS
src/ls.c
tests/local.mk
tests/ls/symlink-quote.sh [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index 6b6cafdae98ff4c73e07129f7d8f522b34b811eb..d37195e2ddcf96b8970465d2db06c3f3fa494b7b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -45,6 +45,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   Previously it would have always returned the 'EXIT' name.
   [bug introduced in fileutils-4.1.9]
 
+  ls now quotes symlink targets consistently.  Previously it may not
+  have quoted the target name if the link name itself didn't need quoting.
+  [bug introduced in coreutils-8.26]
+
   split no longer exits when invocations of a --filter return EPIPE.
   [bug introduced in coreutils-8.26]
 
index 4802d9218c65cb6073a6d9c88aa72ce50a375038..bb97e98a7940ac6e74337cad757daeb1b0777f7d 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -3234,6 +3234,11 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
           get_link_name (absolute_name, f, command_line_arg);
           char *linkname = make_link_name (absolute_name, f->linkname);
 
+          /* Use the slower quoting path for this entry, though
+             don't update CWD_SOME_QUOTED since alignment not affected.  */
+          if (linkname && f->quoted == 0 && needs_quoting (f->linkname))
+            f->quoted = -1;
+
           /* Avoid following symbolic links when possible, ie, when
              they won't be traced and when no indicator is needed.  */
           if (linkname
index 8fc48c48928dced12c510cc3e4d958c873685bb1..fd4713d77816359b4e63747d882638f121d5374e 100644 (file)
@@ -603,6 +603,7 @@ all_tests =                                 \
   tests/ls/stat-free-color.sh                  \
   tests/ls/stat-free-symlinks.sh               \
   tests/ls/stat-vs-dirent.sh                   \
+  tests/ls/symlink-quote.sh                    \
   tests/ls/symlink-slash.sh                    \
   tests/ls/time-style-diag.sh                  \
   tests/ls/x-option.sh                         \
diff --git a/tests/ls/symlink-quote.sh b/tests/ls/symlink-quote.sh
new file mode 100755 (executable)
index 0000000..d792d96
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh
+# Ensure symlinks are quoted appropriately
+
+# Copyright (C) 2017 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 <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ ls
+
+ln -s 'needs quoting' symlink || framework_failure_
+
+ls -l --quoting-style='shell-escape' symlink >out || fail=1
+
+# Coreutils v8.26 and 8.27 failed to quote the target name
+grep -q "symlink -> 'needs quoting'\$" out ||
+  { cat out; fail=1; }
+
+Exit $fail