]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
test: cp: add test for non-UTF8 directory names
authorSylvestre Ledru <sylvestre@debian.org>
Sat, 28 Feb 2026 08:16:57 +0000 (09:16 +0100)
committerPádraig Brady <P@draigBrady.com>
Mon, 2 Mar 2026 11:44:14 +0000 (11:44 +0000)
Missing test identified here:
 https://github.com/uutils/coreutils/pull/11148

* tests/cp/non-utf8-name.sh: Add a new test to cover this case.
https://github.com/coreutils/coreutils/pull/207

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

diff --git a/tests/cp/non-utf8-name.sh b/tests/cp/non-utf8-name.sh
new file mode 100755 (executable)
index 0000000..d404b33
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/sh
+# Ensure cp handles dirs with non-UTF8 names when using recursive copy with dot
+# This test covers the case where a directory name contains non-UTF8 bytes
+
+# Copyright (C) 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_ cp
+
+non_utf8_dir=$(bad_unicode)
+mkdir "$non_utf8_dir" target \
+  || skip_ 'bad unicode not supported in shell or file system'
+
+# Create some test files in the non-UTF8 directory
+touch "$non_utf8_dir"/file1 "$non_utf8_dir"/file2 || framework_failure_
+
+for loc in C "$LOCALE_FR" "$LOCALE_FR_UTF8"; do
+  test -z "$loc" && continue
+  export LC_ALL="$loc"
+
+  # Test: copy contents of non-UTF8 directory using /. syntax
+  # This should work without panicking or erroring
+  cp -r "$non_utf8_dir"/. target || fail=1
+
+  # Verify the files were copied correctly
+  rm target/file1 || fail=1
+  rm target/file2 || fail=1
+
+  # Verify original files still exist
+  test -f "$non_utf8_dir"/file1 || fail=1
+  test -f "$non_utf8_dir"/file2 || fail=1
+done
+
+Exit $fail
index b9f5b897aa8eaac882fef1695fe508836e1cf150..4e18771f48903754954808564e29f008173dfeba 100644 (file)
@@ -562,6 +562,7 @@ all_tests =                                 \
   tests/cp/link-preserve.sh                    \
   tests/cp/link-symlink.sh                     \
   tests/cp/nfs-removal-race.sh                 \
+  tests/cp/non-utf8-name.sh                    \
   tests/cp/no-deref-link1.sh                   \
   tests/cp/no-deref-link2.sh                   \
   tests/cp/no-deref-link3.sh                   \