diff --git a/tests/local.mk b/tests/local.mk index 49f81ba8e..b9f5b897a 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -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 index 000000000..e825af632 --- /dev/null +++ b/tests/ls/non-utf8-hidden.sh @@ -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 . + +. "${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