uutils / uutils/coreutils

tr: bad error priority between overlong set2 and offset mismatch upper/lower

Open
#6,566 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - tr
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

This is just a minor issue about which error takes precedence.

In particular, the following invocation of tr is invalid for three different reasons:

  • The usages of [:upper:] and [:lower:] are misaligned.
  • SET2 ends up way too long (expected 256 - 26 = 230, but 256 are provided).
  • SET2 has more than one unique character.

It probably doesn't matter too much, but our error-behavior differs from GNU.

$ x230="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$ echo -n 'hello' | tr -c '[:upper:]' "${x230}[:lower:]"
tr: when translating with complemented character classes,
string2 must map all characters in the domain to one
[$? = 1]
$ echo -n 'hello' | cargo run -q tr -c '[:upper:]' "${x230}[:lower:]"
tr: when translating, every 'upper'/'lower' in set2 must be matched by a 'upper'/'lower' in the same position in set1
[$? = 1]

I believe our error message is actually the better one, so feel free to close this as "WONTFIX". Or do we want to exactly match GNU tr even in error message priority? (In some other tools we do!)

(Found while reviewing #6564.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two shown tr invocations and comparing their diagnostics with GNU tr. The issue names no source file or test; completion requires deciding the intended error precedence and documenting or testing that behavior before making any change.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.