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

join: operate on bytes instead of Strings #2851

Merged
merged 3 commits into from
Jan 16, 2022

Conversation

jtracey
Copy link
Contributor

@jtracey jtracey commented Jan 5, 2022

This PR switches join from operating on Strings to operating on bytes.
This more closely matches the GNU behavior, but comes at some cost. The high level points are:

  • something like this is necessary to allow GNU's 8-bit-t test to pass, which checks that an 8-bit (invalid Unicode) separator can be used
  • it generally allows nearly arbitrary binary files to be used, even more so once the -z option is added (an easy change once this is merged) -- something that can't be safely done with Rust String operations
  • current support for multi-byte (but single character) separators is lost, as they are in GNU's join
  • similarly, the -i flag no longer functions for non-ASCII letters
  • Windows-style newlines (CR LF, \r\n) are now treated as two separate characters (again, matching GNU's join behavior)

If the coreutils were designed today, there might have been different choices made, but if the goal is a drop-in replacement for GNU, this change is necessary.

Note that this does not get the 8-bit-t test to actually pass, as that's blocked on upgrading to clap 3.0 for the allow_invalid_utf8() method. It does incidentally fix sp-vs-blank, since we're now explicitly splitting on certain values, rather than relying on Rust's default whitespace detection. Related: #2634

Part of switching from Strings to Vec is replacing calls to print!(...)/println!(...) to stdout().write_all(...), which involves more explicit error handling, so that's where a lot of the diff comes from.

@jtracey jtracey mentioned this pull request Jan 5, 2022
10 tasks
@sylvestre
Copy link
Sponsor Contributor

Would you please add tests for this?

@jtracey
Copy link
Contributor Author

jtracey commented Jan 9, 2022

My original thinking was that this was supposed to be an internal change, but it does fix a few bugs, so I was able to add two tests after all. The binary files in the latter are formatted such that they can be reused for testing -z, -t'\0', and non-Unicode -t values, once those get added.

@sylvestre sylvestre merged commit 00c11b1 into uutils:master Jan 16, 2022
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.

None yet

2 participants