-
Notifications
You must be signed in to change notification settings - Fork 5
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
unicode control characters trigger debug_assert_eq
#16
Comments
(this was likely introduced in |
This is a legit logic error caught by The problem is that we control char to be of width 0 here: Line 155 in 9e49ef4
But unicode-width treats control char as width 1 via unicode-rs/unicode-width#45 |
Aetf
added a commit
that referenced
this issue
Jun 24, 2024
This is consistent with how unicode-width handles string width vs char width. See also unicode-rs/unicode-width#45
Aetf
added a commit
that referenced
this issue
Jun 24, 2024
This is consistent with how unicode-width handles string width vs char width. See also unicode-rs/unicode-width#45
Merged
Thanks a ton |
Aetf
pushed a commit
that referenced
this issue
Jul 9, 2024
## 🤖 New release * `unicode-truncate`: 1.0.0 -> 1.1.0 <details><summary><i><b>Changelog</b></i></summary><p> <blockquote> ## [1.1.0](v1.0.0...v1.1.0) - 2024-07-08 ### Added - segment by graphemes ([#11](#11)) ### Fixed - *(deps)* update rust crate itertools to 0.13 ([#20](#20)) - fixed typos in the `renovate.json` ([#17](#17)) ### Other - Removed unnessary debug-assertions setting - Treat control characters as width 1, fixes [#16](#16) ([#19](#19)) - tweak renovate configs ([#13](#13)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/MarcoIeni/release-plz/). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
Thanks for writing the truncation code ^^
During testing of this library, I noticed that carefully crafted inputs containing control caracters can trigger an assertion. This only happens in in debug mode => not a runtime panic for release. The used character is
End of Medium
.The assertion is located here
unicode-truncate/src/lib.rs
Line 174 in 9e49ef4
A minimal (failing) testcase is the following
This happens because at said point (expanded for better readability)
result.width()
(=1) is larger than thenew_width
(=0).This case happens as
(self.len(), 0)
is appended to the interator.This makes the iterator (as intended by the doccomment) eager for trailing zero width characters.
=> The asserted invariant does not hold anymore.
A possible fix would be to change the assertion to
I can provide a PR with this fix if you'd prefer this
The text was updated successfully, but these errors were encountered: