I submitted the fix upstream in uutils/coreutils PR #15031:
https://github.com/uutils/coreutils/pull/15031

The problem was that Sequence::parse_set called parse_char_range before
bracketed constructs in alt((...)). For '[-*]', parse_char_range matched
'[' as start, '-' as delimiter, and '*' as end. Because '[' > '*', it
failed with BadSequence::BackwardsRange before parse_char_star could
run.

Moving parse_char_range after the bracketed constructs fixes the issue.

Attached debdiff for rust-coreutils 0.12.0-1ubuntu3 in stonking:
- Adds d/p/tr-bracketed-constructs-precedence.patch with DEP-3 headers linked 
to upstream PR #15031 and LP #2169227.
- Adds regression test test_repeat_hyphen in tests/by-util/test_tr.rs.
- All 174 tr integration tests pass with 0 failures.
- Verified on reproducer:
  echo "Base Z" | tr -s '[:blank:]' '[-*]'
  Outputs "Base-Z" with exit code 0.


** Description changed:

+ [ Impact ]
+ 
+ In Ubuntu devel (stonking), rust-coreutils provides tr. When parsing SET2 in 
tr, repeat constructs of the form [c*] where c is a hyphen '-' (for example 
'[-*]') fail with:
+   tr: range-endpoints of '[-*' are in reverse collating sequence order
+ 
+ GNU tr accepts this syntax. This incompatibility causes basez to fail to 
build from source (FTBFS) during ./configure, where line 27 runs:
+   PKGNAME=`echo "$APPNAME" |tr '[:upper:]' '[:lower:]' |tr -s '[:blank:]' 
'[-*]'`
+ 
+ Because tr aborts, PKGNAME is empty and the build stops with:
+   Makefile:35: *** PKGNAME is missing. Stop.
+ 
+ [ Fix ]
+ 
+ In src/uu/tr/src/operation.rs (Sequence::parse_set), the parser
+ alternatives used alt((Self::parse_char_range, Self::parse_char_star,
+ ...)). Because parse_char_range ran before bracketed constructs, it
+ matched '[' as start char, '-' as range delimiter, and '*' as end char.
+ Since '[' (ASCII 91) is greater than '*' (ASCII 42), parse_char_range
+ failed with BadSequence::BackwardsRange and stopped alt from trying
+ parse_char_star.
+ 
+ Moving parse_char_range after the bracketed constructs (parse_char_star,
+ parse_char_repeat, parse_class, parse_char_equal) fixes the issue.
+ Bracketed constructs are now recognized before character ranges.
+ Regression test test_repeat_hyphen added to tests/by-util/test_tr.rs.
+ 
+ [ Test Plan ]
+ 
+ 1. Run repeat construct with hyphen:
+    echo "Base Z" | /usr/bin/tr -s '[:blank:]' '[-*]'
+    Expected stdout: "Base-Z"
+    Expected exit code: 0
+ 
+ 2. Run repeat construct with count:
+    echo "Base Z" | /usr/bin/tr -s '[:blank:]' '[-*5]'
+    Expected stdout: "Base-Z"
+    Expected exit code: 0
+ 
+ 3. Verify standard character ranges still work:
+    echo "abc" | /usr/bin/tr 'a-c' 'x-z'
+    Expected stdout: "xyz"
+    Expected exit code: 0
+ 
+ 4. Verify full tr integration test suite:
+    cargo test --package coreutils --test tests test_tr::
+    Expected result: 174 passed, 0 failed.
+ 
+ [ Where problems could occur ]
+ 
+ The change adjusts the priority of parser alternatives in
+ Sequence::parse_set. Bracketed constructs ([c*], [c*n], [:class:],
+ [=c=]) require bracket delimiters and are more specific than unbracketed
+ ranges. If a malformed bracketed expression is parsed, it now reports a
+ syntax error rather than falling back to character range parsing.
+ Standard character ranges (such as a-z) are unaffected.
+ 
+ [ Other Info ]
+ 
+ - Upstream Pull Request: https://github.com/uutils/coreutils/pull/15031
+ - Target series: Ubuntu devel (stonking, 26.10).
+ - Target package version: rust-coreutils 0.12.0-1ubuntu3.
+ - Test suite: full test_tr test suite passes (174 passed, 0 failed, 0 
regressions).
+ 
+ --- [ Original Report ]
+ 
  uutils tr rejects a "[c*]" repeat construct in SET2 when the repeated
  character is '-'. GNU tr accepts it. This makes basez fail to build from
  source in stonking.
  
  == Reproducer ==
  
    echo "Base Z" | tr -s '[:blank:]' '[-*]'
  
  GNU coreutils: prints "Base-Z"
  rust-coreutils 0.12.0-1ubuntu1 (from the build log below):
    tr: range-endpoints of '[-*' are in reverse collating sequence order
  
  In POSIX/GNU tr, "[c*]" in SET2 means "repeat c until SET2 is as long as
  SET1", so '[-*]' means "replace with '-'". uutils seems to parse "[-*"
  as a range from '[' to '*' before it recognises the repeat construct.
  uutils handles "[c*]" with ordinary characters, so the problem seems
  specific to '-' (and possibly other characters that are special in range
  syntax).
  
  Note: the uutils output above comes from the build log; this was not re-
  run directly against a uutils binary.
  
  == Impact ==
  
  basez 1.6.2-3build1 fails to build on all architectures in stonking (and 
failed in resolute):
  https://launchpad.net/ubuntu/+source/basez/1.6.2-3build1/+build/32793382
  
  Its configure script (line 27) does:
  
    PKGNAME=`echo "$APPNAME" |tr '[:upper:]' '[:lower:]' |tr -s
  '[:blank:]' '[-*]'`
  
  With uutils tr, PKGNAME ends up empty and the build stops:
  
    tr: range-endpoints of '[-*' are in reverse collating sequence order
    ...
    Makefile:35: *** PKGNAME is missing.  Stop.
  
  The build environment has coreutils-from-uutils 2ubuntu1 and rust-
  coreutils 0.12.0-1ubuntu1. Debian (GNU coreutils) is not affected.
  
  Other packages that use '[-*]' (or similar repeats of a range-special
  character) in tr calls are likely affected too.
  
  == Workaround ==
  
  In basez, replacing '[-*]' with '-' gives the same result with both
  implementations. The tr incompatibility should still be fixed in uutils;
  I did not find an existing upstream issue for it.

** Changed in: rust-coreutils (Ubuntu)
       Status: New => Confirmed

** Changed in: basez (Ubuntu)
       Status: New => Confirmed

** Tags added: ftbfs patch stonking

** Patch added: "rust-coreutils 0.12.0-1ubuntu3 debdiff for stonking"
   
https://bugs.launchpad.net/ubuntu/+source/rust-coreutils/+bug/2169227/+attachment/6004824/+files/rust-coreutils_0.12.0-1ubuntu3.debdiff

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2169227

Title:
  tr: '[-*]' repeat construct in SET2 rejected as reversed range (breaks
  basez FTBFS)

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/basez/+bug/2169227/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to