Skip to content

tr: accept an unused upper/lower class past the end of set1 - #16764

Merged
cakebaker merged 1 commit into
uutils:mainfrom
Xnadir:tr-unused-case-class
Nov 23, 2026
Merged

cakebaker merged 1 commit into
uutils:mainfrom
Xnadir:tr-unused-case-class

Conversation

@Xnadir

@Xnadir Xnadir commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #15589 (case 3; cases 1 and 2 already behave like GNU on main since #15652).

When translating, every [:upper:]/[:lower:] in set2 had to line up with one in set1, even a class that starts past the end of set1 and is never used. GNU only checks a class that starts at or before the end of set1:

$ printf 'xaAbB\n' | tr a 'ab[:lower:]'    # GNU: xaAbB, exit 0
$ printf 'xaAbB\n' | tr a 'b[:lower:]'     # GNU: misaligned [:upper:] and/or [:lower:] construct, exit 1
$ printf 'xaAbB\n' | tr ab 'xy[:lower:]'   # GNU: misaligned ..., exit 1
$ printf 'xaAbB\n' | tr ab 'xyz[:lower:]'  # GNU: xxAyB, exit 0

The alignment check now skips a class whose position in set2 is greater than set1's length. A class starting right at the end of set1 is still refused, as GNU does.

I compared 11 command lines with GNU tr (output and exit code), including the four above, a range in set1, a class followed by a character, and [:upper:]/[:lower:] in both sets, and all now match. The new test_unused_upper_lower_past_set1_is_accepted cases fail on main, and two class_at_end_of_set1 cases were added to test_misaligned_upper_lower_construct to pin the boundary. cargo test --features tr --no-default-features -- test_tr:: passes (197), and cargo clippy -p uu_tr --target x86_64-unknown-linux-gnu -- -D warnings is clean.

This change was written with the help of an AI assistant (Claude); I reviewed and tested it.

🤖 Generated with Claude Code

When translating, every [:upper:] or [:lower:] in set2 had to line up with one in set1, even a class that starts past the end of set1 and is never used. GNU only checks a class that starts at or before the end of set1, so tr a 'ab[:lower:]' translates there and failed here with "misaligned [:upper:] and/or [:lower:] construct".

Fixes uutils#15589
Copilot AI balanced review requested due to automatic review settings November 22, 2026 15:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@cakebaker
cakebaker merged commit 375f1a0 into uutils:main Nov 23, 2026
104 of 106 checks passed
@cakebaker

Copy link
Copy Markdown
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tr: [c*] accepted with -d -s, [=c=] accepted in string2 when translating, and a case class past the end of string1 rejected

3 participants