Skip to content

tr: check a complemented SET1 the way GNU does - #15009

Open
Socialpranker wants to merge 2 commits into
uutils:mainfrom
Socialpranker:tr-complement-check-order
Open

Socialpranker wants to merge 2 commits into
uutils:mainfrom
Socialpranker:tr-complement-check-order

Conversation

@Socialpranker

Copy link
Copy Markdown
Contributor

With -c, uutils checks SET2's [:upper:]/[:lower:] against positions in SET1, but a complemented SET1 has no such positions. It also reports the complement rule before the "longer than SET2" rule. Found by diffing against GNU 9.12:

$ echo AbC1z | tr -c '[:upper:]' '[:lower:]'
tr: when translating with string1 longer than string2,     # GNU
the latter string must not end with a character class
tr: when translating with complemented character classes,  # uutils
string2 must map all characters in the domain to one

$ echo AbC1z | tr -c '\000-\377' '[:upper:]'
AbC1z                                                      # GNU
tr: when translating, every 'upper'/'lower' in set2 must   # uutils
be matched by a 'upper'/'lower' in the same position in set1

The fix skips the alignment check under -c and runs the complement check after the length check. Tests added in test_tr.rs.

@xtqqczze

This comment was marked as outdated.

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/tail/follow-name is no longer failing!
Congrats! The gnu test tests/tail/pid-pipe is no longer failing!

@github-actions

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 155.24 MB (-148 KB, -0.09%)

Significant per-binary changes:
  env     1.20 MB ->    1.28 MB  (+80 KB, +6.51%)

tr exits before reading stdin there, so writing it raced with the exit
and could fail with a broken pipe.
@sylvestre
sylvestre force-pushed the tr-complement-check-order branch from b70decb to cc1fe7f Compare November 19, 2026 08:41

This branch has not been deployed

No deployments
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.

2 participants