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: Correctly "fill" set2 in case of complement #6344

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

tr: Correctly "fill" set2 in case of complement #6344

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

Comments

@BenWiederhake
Copy link
Collaborator

In a STRING with 256 given characters and [y*], this "repeated character" should expand to the empty string "". With only 255 given characters, it should expand to "y", i.e. a single character.

$ x226="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$ echo -n 'hello' | ../gnu/src/tr -c '[:upper:]' ${x226}'[y*]xxx' # "[y*]" expands to "y", and now set2 contains two distinct characters.
../gnu/src/tr: when translating with complemented character classes,
string2 must map all characters in the domain to one
[$? = 1]
$ echo -n 'hello' | ../gnu/src/tr -c '[:upper:]' ${x226}'[y*]xxxx' # "[y*]" expands to "", so set2 contains only one distinct character.
xxxxx
$ echo -n 'hello' | cargo run tr -c '[:upper:]' ${x226}'[y*]xxxx' # We handle the "" case correctly, accidentally.
xxxxx
$ echo -n 'hello' | cargo run tr -c '[:upper:]' ${x226}'[y*]xxx' # \342\200\246 but we fail in the "y" case.
xxxxx

There are some other ways to detect it, but this is probably the easiest way.

(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