Skip to content

Commit c75fff5

Browse files
sylvestrepixelb
authored andcommitted
test: cp: add test for non-UTF8 directory names
Missing test identified here: uutils/coreutils#11148 * tests/cp/non-utf8-name.sh: Add a new test to cover this case. #207
1 parent 69c0b63 commit c75fff5

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

tests/cp/non-utf8-name.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/sh
2+
# Ensure cp handles dirs with non-UTF8 names when using recursive copy with dot
3+
# This test covers the case where a directory name contains non-UTF8 bytes
4+
5+
# Copyright (C) 2026 Free Software Foundation, Inc.
6+
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
20+
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
21+
print_ver_ cp
22+
23+
non_utf8_dir=$(bad_unicode)
24+
mkdir "$non_utf8_dir" target \
25+
|| skip_ 'bad unicode not supported in shell or file system'
26+
27+
# Create some test files in the non-UTF8 directory
28+
touch "$non_utf8_dir"/file1 "$non_utf8_dir"/file2 || framework_failure_
29+
30+
for loc in C "$LOCALE_FR" "$LOCALE_FR_UTF8"; do
31+
test -z "$loc" && continue
32+
export LC_ALL="$loc"
33+
34+
# Test: copy contents of non-UTF8 directory using /. syntax
35+
# This should work without panicking or erroring
36+
cp -r "$non_utf8_dir"/. target || fail=1
37+
38+
# Verify the files were copied correctly
39+
rm target/file1 || fail=1
40+
rm target/file2 || fail=1
41+
42+
# Verify original files still exist
43+
test -f "$non_utf8_dir"/file1 || fail=1
44+
test -f "$non_utf8_dir"/file2 || fail=1
45+
done
46+
47+
Exit $fail

tests/local.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ all_tests = \
562562
tests/cp/link-preserve.sh \
563563
tests/cp/link-symlink.sh \
564564
tests/cp/nfs-removal-race.sh \
565+
tests/cp/non-utf8-name.sh \
565566
tests/cp/no-deref-link1.sh \
566567
tests/cp/no-deref-link2.sh \
567568
tests/cp/no-deref-link3.sh \

0 commit comments

Comments
 (0)