From: Sylvestre Ledru Date: Sat, 28 Feb 2026 08:16:57 +0000 (+0100) Subject: test: cp: add test for non-UTF8 directory names X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c75fff50f6d668c4161fec63b54beb41917d4016;p=thirdparty%2Fcoreutils.git test: cp: add test for non-UTF8 directory names 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 --- diff --git a/tests/cp/non-utf8-name.sh b/tests/cp/non-utf8-name.sh new file mode 100755 index 0000000000..d404b3313f --- /dev/null +++ b/tests/cp/non-utf8-name.sh @@ -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 . + +. "${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 diff --git a/tests/local.mk b/tests/local.mk index b9f5b897aa..4e18771f48 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -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 \