]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: ls: treat invalid UTF-8 paths starting with a dot as hidden
authorSylvestre Ledru <sylvestre@debian.org>
Fri, 27 Feb 2026 08:23:17 +0000 (09:23 +0100)
committerPádraig Brady <P@draigBrady.com>
Sat, 28 Feb 2026 20:18:57 +0000 (20:18 +0000)
* tests/ls/non-utf8-hidden.sh: Add the test case.
https://github.com/uutils/coreutils/pull/11135
https://github.com/coreutils/coreutils/pull/202

tests/local.mk
tests/ls/non-utf8-hidden.sh [new file with mode: 0755]

index 49f81ba8e09bb0ad0719daf7fdfcf0671045c5eb..b9f5b897aa8eaac882fef1695fe508836e1cf150 100644 (file)
@@ -694,6 +694,7 @@ all_tests =                                 \
   tests/ls/w-option.sh                         \
   tests/ls/multihardlink.sh                    \
   tests/ls/no-arg.sh                           \
+  tests/ls/non-utf8-hidden.sh                  \
   tests/ls/selinux-segfault.sh                 \
   tests/ls/quote-align.sh                      \
   tests/ls/size-align.sh                       \
diff --git a/tests/ls/non-utf8-hidden.sh b/tests/ls/non-utf8-hidden.sh
new file mode 100755 (executable)
index 0000000..e825af6
--- /dev/null
@@ -0,0 +1,60 @@
+#!/bin/sh
+# Test that files starting with a dot are treated as hidden
+# even with invalid UTF-8
+
+# Copyright 2026 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 <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ ls
+
+mkdir d || framework_failure_
+echo "content" > d/visible || framework_failure_
+
+# Create a hidden file with valid UTF-8
+touch d/.hidden_valid || framework_failure_
+
+# Create a hidden file with invalid UTF-8 (without trailing newline)
+printf 'content\n' > d/$(printf '.hidden_invalid%s' "$(bad_unicode)") \
+  || skip_ 'bad unicode not supported in shell or file system'
+
+for loc in C "$LOCALE_FR" "$LOCALE_FR_UTF8"; do
+  test -z "$loc" && continue
+  export LC_ALL="$loc"
+
+  # Test 1: Without -a flag, only visible file should appear
+  ls d > out1 || fail=1
+  echo 'visible' > exp1
+  compare exp1 out1 || fail=1
+
+  # Test 2: With -a flag, all files including hidden ones should appear
+  # The invalid UTF-8 filename will be shown in some escaped form
+  ls -a d > out2 || fail=1
+
+  # Check that we have at least 5 entries (., .., visible, and 2 hidden files)
+  line_count=$(wc -l < out2)
+  test "$line_count" -ge 5 || fail=1
+
+  # Test 3: Verify the visible file is still there with -a
+  grep -F "visible" out2 > /dev/null || fail=1
+
+  # Test 4: Verify the valid hidden file appears with -a
+  grep -F ".hidden_valid" out2 > /dev/null || fail=1
+
+  # Test 5: Verify the invalid hidden file appears with -a
+  grep -F ".hidden_invalid" out2 > /dev/null || fail=1
+done
+
+Exit $fail