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: Raise error when STRING2 argument has unreachable character during complement #6345

Open
BenWiederhake opened this issue May 4, 2024 · 0 comments
Labels

Comments

@BenWiederhake
Copy link
Collaborator

When complementing, we basically translate all bytes not mentioned in STRING1 to bytes in STRING2. This means that only the first 256-len(ARRAYISH1) bytes of ARRAY2 can be accessed.

GNU tr issues a (confusing, but well-intentioned) error message if the command-line argument contains garbage:

$ x230="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$ echo -n 'hello' | ../gnu/src/tr -c '[:upper:]' "${x230}" # 256-26 times 'x'
xxxxx
$ echo -n 'hello' | ../gnu/src/tr -c '[:upper:]' "${x230}x" # 256-26+1 times 'x'
../gnu/src/tr: when translating with complemented character classes,
string2 must map all characters in the domain to one
[$? = 1]
$ echo -n 'hello' | cargo run tr -c '[:upper:]' "${x230}" # we accidentally treat this correctly
xxxxx
$ echo -n 'hello' | cargo run tr -c '[:upper:]' "${x230}x" # this needs to change
xxxxx

Computing the ideal size should be easy, but checking it isn't:

  • If we just consider the length of STRING2, then this will obviously fail due to expansions
  • I believe there was some reason why checking the length of ARRAY2 didn't work. Hmm. I'm confused.

(Original issue: #6133)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant