aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorCollin Funk <collin.funk1@gmail.com>2025-08-25 23:15:21 -0700
committerCollin Funk <collin.funk1@gmail.com>2025-08-26 16:59:32 -0700
commitae89cd646a7dfd0cf655e8c0d0d56b93288abb71 (patch)
tree43229cad147335fe1e38709de25a4f61d65bada0 /tests
parenttests: fold: consolidate all fold tests in tests/fold (diff)
downloadcoreutils-ae89cd646a7dfd0cf655e8c0d0d56b93288abb71.tar.gz
coreutils-ae89cd646a7dfd0cf655e8c0d0d56b93288abb71.zip
fold: don't truncate multibyte characters at the end of the buffer
* src/fold.c (fold_file): Replace invalid characters with the original byte read. Copy multibyte sequences that may not yet be read to the start of the buffer before reading more bytes. * tests/fold/fold-characters.sh: Add a test case.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/fold/fold-characters.sh19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/fold/fold-characters.sh b/tests/fold/fold-characters.sh
index 159f6ddac..be17d80be 100755
--- a/tests/fold/fold-characters.sh
+++ b/tests/fold/fold-characters.sh
@@ -58,6 +58,25 @@ compare column-exp2 column-out2 || fail=1
fold --characters -w 10 input2 > character-out2 || fail=1
compare character-exp2 character-out2 || fail=1
+# Test a Unicode character on the edge of the input buffer.
+# Keep in sync with IO_BUFSIZE - 1.
+yes a | head -n 262143 | tr -d '\n' > input3 || framework_failure_
+env printf '\uB250' >> input3 || framework_failure_
+yes a | head -n 100 | tr -d '\n' >> input3 || framework_failure_
+env printf '\n' >> input3 || framework_failure_
+
+yes a | head -n 80 | tr -d '\n' > exp3 || framework_failure_
+env printf '\n' >> exp3 || framework_failure_
+yes a | head -n 63 | tr -d '\n' >> exp3 || framework_failure_
+env printf '\uB250' >> exp3 || framework_failure_
+yes a | head -n 16 | tr -d '\n' >> exp3 || framework_failure_
+env printf '\n' >> exp3 || framework_failure_
+yes a | head -n 80 | tr -d '\n' >> exp3 || framework_failure_
+env printf '\naaaa\n' >> exp3 || framework_failure_
+
+fold --characters input3 | tail -n 4 > out3 || fail=1
+compare exp3 out3 || fail=1
+
# Ensure bounded memory operation
vm=$(get_min_ulimit_v_ fold /dev/null) && {
yes | tr -d '\n' | (ulimit -v $(($vm+8000)) && fold 2>err) | head || fail=1