Skip to content

tr: fix complemented class truncation ordering#11406

Merged
sylvestre merged 3 commits intouutils:mainfrom
can1357:tr-fix-complemented-class-truncation-ordering
Apr 20, 2026
Merged

tr: fix complemented class truncation ordering#11406
sylvestre merged 3 commits intouutils:mainfrom
can1357:tr-fix-complemented-class-truncation-ordering

Conversation

@can1357
Copy link
Copy Markdown
Contributor

@can1357 can1357 commented Mar 18, 2026

uutils tr applies the complemented-character-class guard before --truncate-set1, then truncates the translated set afterward. That allows -ct to translate only a subset of complemented bytes, while GNU rejects this shape instead of allowing partial mapping.

Reproduction Steps

printf A | tr -ct '[:digit:]' X
# Expected (GNU): exit 1 with "when translating with complemented character classes, string2 must map all characters in the domain to one"
# Actual (uutils): exit 0 & outputs "A"

Impact

This breaks GNU compatibility and weakens sanitization pipelines that rely on tr -ct to enforce translation coverage. Inputs that should be rejected can be accepted with under-filtered output.

Comment thread tests/by-util/test_tr.rs
Comment on lines +344 to +351
#[test]
fn test_truncate_applies_before_complement_with_class() {
new_ucmd!()
.args(&["-ct", "[:digit:]", "X"])
.pipe_in("A")
.succeeds()
.stdout_is("X");
}
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.

This test is incorrect because it contradicts your reproduction steps:

printf A | tr -ct '[:digit:]' X
# Expected (GNU): exit 1 with "when translating with complemented character classes, string2 must map all characters in the domain to one"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

my bad, it's the rejection test. will push the inverse

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.

@can1357 did you fix it? thanks

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

GNU testsuite comparison:

Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)

@sylvestre sylvestre merged commit 98f6b01 into uutils:main Apr 20, 2026
169 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants