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 does not handle escape sequences correct #1817

Closed
SuperSandro2000 opened this issue Mar 14, 2021 · 1 comment · Fixed by #1833
Closed

tr does not handle escape sequences correct #1817

SuperSandro2000 opened this issue Mar 14, 2021 · 1 comment · Fixed by #1833

Comments

@SuperSandro2000
Copy link
Contributor

autoconf relies on the following snippet to generate a CRLF character:

echo X | tr X '\015'

which is broken in uutils-coreutils and returns a 0:

uutils-tr

$ echo X | tr X '\015' | /bin/xxd
00000000: 300a                                     0.

gnus tr:

echo X | tr X '\015' | /bin/xxd
00000000: 0d0a                                     ..
@cole-h
Copy link

cole-h commented Mar 14, 2021

This seems to stem from here:

'\\' if self.string.len() > 1 => {
// yes---it's \ and it's not the last char in a string
// we know that \ is 1 byte long so we can index into the string safely
let c = self.string[1..].chars().next().unwrap();
(Some(unescape_char(c)), 1 + c.len_utf8())

which only handles characters (e.g. it's only parsing the 0, where it should be parsing the whole thing as an octal). This could be solved by making unescape take &str and then checking if the &str starts with \ (and continue with that).

There would probably need to be "specialized" parsing for \u and \x, as well as octal (with support for those with and without leading octal numbers). POSIX tr doesn't specify \u and \x, so this is unnecessary.

drocco007 added a commit to drocco007/coreutils that referenced this issue Mar 16, 2021
drocco007 added a commit to drocco007/coreutils that referenced this issue Mar 17, 2021
drocco007 added a commit to drocco007/coreutils that referenced this issue Mar 17, 2021
drocco007 added a commit to drocco007/coreutils that referenced this issue Mar 17, 2021
drocco007 added a commit to drocco007/coreutils that referenced this issue Mar 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants