Skip to content

tr: fix octal interpretation of repeat count string#3178

Merged
tertsdiepraam merged 6 commits intomainfrom
unknown repository
Feb 25, 2022
Merged

tr: fix octal interpretation of repeat count string#3178
tertsdiepraam merged 6 commits intomainfrom
unknown repository

Conversation

@ghost
Copy link

@ghost ghost commented Feb 22, 2022

Closes #3168

Fix repeat count processing of tr to interpret as octal only if prefixed with 0.

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clippy and spelling check found some issues, but looks like it's going in the right direction! Thanks!

Comment on lines 282 to 287
let result: Result<usize, ParseIntError>;
if cnt_str.chars().next().unwrap() == '0' {
result = usize::from_str_radix(cnt_str, 8);
} else {
result = usize::from_str_radix(cnt_str, 10);
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let result: Result<usize, ParseIntError>;
if cnt_str.chars().next().unwrap() == '0' {
result = usize::from_str_radix(cnt_str, 8);
} else {
result = usize::from_str_radix(cnt_str, 10);
};
let result = cnt_str.starts_with('0') {
usize::from_str_radix(cnt_str, 8);
} else {
usize::from_str_radix(cnt_str, 10);
};

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it. Do you know how can I fix the below?

Error: ERROR: Unknown word (abcdefghijkl) (file:'tests/by-util/test_tr.rs', line:876)
Error: ERROR: Unknown word (xxxxxxxxyyyymnop) (file:'tests/by-util/test_tr.rs', line:879)
Error: ERROR: Unknown word (abcdefghijkl) (file:'tests/by-util/test_tr.rs', line:886)
Error: ERROR: Unknown word (xxxxxxxxxxyymnop) (file:'tests/by-util/test_tr.rs', line:889)
Error: Process completed with exit code 1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! You can add those "words" to the // spell-checker:ignore comments in that file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR has way too many commits than I wanted. Will you be able to squash them while merging or should I try to squash them and send another PR?

Also, please review and let me know if this looks okay.

@tertsdiepraam tertsdiepraam merged commit b8a3795 into uutils:main Feb 25, 2022
@tertsdiepraam
Copy link
Member

All good! Thanks!

@ghost ghost deleted the fix-tr-repeat branch March 2, 2022 17:07
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 this pull request may close these issues.

tr: Incorrect parsing of the repeat count in [c*n]

1 participant