dash 0.5.13 to 0.5.13.5 at least has a variable expansion bug:
https://bugzilla.redhat.com/2568651
This was seen on Fedora 44 and there is no upstream dash
release with a fix yet.

* init.cfg (bad_unicode): Avoid the dash issue, by comparing
the variable expansion and skipping upon mismatch.
* tests/du/block-size.sh: Add explicit checks for expansion
on values with high bit set.
* tests/paste/multi-byte.sh: Likewise.
---
 init.cfg                  | 11 ++++++++++-
 tests/du/block-size.sh    |  3 +++
 tests/paste/multi-byte.sh |  5 +++++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/init.cfg b/init.cfg
index 531bc386e..197ab4481 100644
--- a/init.cfg
+++ b/init.cfg
@@ -888,7 +888,16 @@ bad_unicode ()
   require_built_ printf
 
   # invalid UTF8|unpaired surrogate|C1 control|noncharacter
-  env printf '\xFF|\xED\xBA\xAD|\u0089|\xED\xA6\xBF\xED\xBF\xBF\n'
+  local format='\xFF|\xED\xBA\xAD|\u0089|\xED\xA6\xBF\xED\xBF\xBF\n'
+  local bytes
+  # Some shells corrupt invalid UTF-8 during variable assignment.
+  # Seen with dash 0.5.13 to 0.5.13.5 at least
+  bytes=$(env printf "$format")
+  if test "$bytes" != "$(env printf "$format")"; then
+    warn_ 'shell cannot preserve invalid Unicode bytes; using ASCII instead'
+    bytes='not_bad_unicode'
+  fi
+  printf '%s\n' "$bytes"
 }
 
 # AIX has a 'strace' program unrelated to the one we care about.  Avoid
diff --git a/tests/du/block-size.sh b/tests/du/block-size.sh
index f4573bef8..086955e8d 100755
--- a/tests/du/block-size.sh
+++ b/tests/du/block-size.sh
@@ -60,6 +60,9 @@ test_unit ()
     { test -z "$loc" || test "$loc" = none; } && continue
     if test $loc != C; then
       thousands_sep=$(LC_ALL=$loc locale thousands_sep)
+      # dash 0.5.13 corrupts non-ASCII bytes during variable assignment.
+      test "$thousands_sep" = "$(LC_ALL=$loc locale thousands_sep)" ||
+        skip_ 'shell cannot preserve locale thousands separator'
       grouping=$(LC_ALL=$loc locale grouping)
       test -z "$thousands_sep" && continue
       test "$grouping" != 3 && continue
diff --git a/tests/paste/multi-byte.sh b/tests/paste/multi-byte.sh
index 85b1443e7..54c51b9dd 100755
--- a/tests/paste/multi-byte.sh
+++ b/tests/paste/multi-byte.sh
@@ -32,6 +32,11 @@ delim_euro=$(env printf '\xe2\x82\xac')
 # UTF-8 test: 4-byte character (e.g., emoji: U+1F600)
 delim_emoji=$(env printf '\xf0\x9f\x98\x80')
 
+# dash 0.5.13 corrupts UTF-8 bytes during variable assignment.
+test "$delim_cent$delim_euro$delim_emoji" = \
+  "$(env printf '\xc2\xa2\xe2\x82\xac\xf0\x9f\x98\x80')" ||
+  skip_ 'shell cannot preserve UTF-8 delimiters'
+
 printf '1\n2\n' > f1 || framework_failure_
 printf 'a\nb\n' > f2 || framework_failure_
 
-- 
2.56.0


Reply via email to