Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tr: imperfect handling of mixed multi-byte UTF-8 character and 8-bit octal operands #365

Open
andrewliebenow opened this issue Oct 26, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@andrewliebenow
Copy link
Contributor

❯ coreutils printf 'ᚱ \xE1' | ./target/release/tr -d 'ᚱ \341' | bat --plain --show-all
\x9A\xB1

Expected output is an empty string. The first byte of ᚱ is 0xE1 (225, or 341 in octal). tr is being asked to delete "ᚱ", but also, separately the byte 225 ("\341"). There may be more bugs of this kind, where a UTF-8 character operand's leading byte is also present separately as an octal operand.

These bugs are unlikely to be practically significant, and can pretty easily be worked around. For instance:

❯ coreutils printf 'ᚱ \xE1' | ./target/release/tr -d 'ᚱ' | ./target/release/tr -d ' \341' | bat --plain --show-all
# No output

Most implementations of tr can handle only binary data or only UTF-8 data at all, whereas this is a minor limitation in simultaneous binary and UTF-8 processing.

As such, this could probably also be marked as an enhancement instead of a bug.

@andrewliebenow andrewliebenow added the bug Something isn't working label Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant