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

Replace unmaintained encoding dependency with encoding_rs #2626

Merged
merged 1 commit into from
Sep 1, 2023

Conversation

rhysd
Copy link
Contributor

@rhysd rhysd commented Jul 21, 2023

bat depends on encoding crate but it is no longer maintained. This is reported as RUSTSEC-2021-0153 in the advisory DB. The advisory suggests encoding_rs crate as alternative.

This PR replaces the unmaintained crate with the alternative.

As a side effect, this patch makes bat's UTF16 support a bit more efficient:

  • Decoding with UTF16LE or UTF16BE is now handled with Cow instead of String. It means that it can avoid extra allocation by reusing the original string buffer when no character in the buffer was replaced while encoding.
  • Removing BOM is now handled by encoding_rs more efficiently thanks to encode_with_bom_removal methods. The previous implementation always allocated new buffer only for removing BOM.

@rhysd rhysd changed the title Replace unmaintained encoding with encoding_rs Replace unmaintained encoding dependency with encoding_rs Jul 21, 2023
Copy link
Owner

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

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

Thank you very much for your contribution!

Also great to see that this makes the code easier.

@sharkdp sharkdp merged commit 1e52785 into sharkdp:master Sep 1, 2023
21 checks passed
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.

2 participants