-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Bug] Panic on truncating non-ASCII content #167
Comments
Here's the issue: We shouldn't truncate a string based on its visual width, as it doesn't correspond to the string's length in bytes.
|
I found back the code I used to have before Himalaya relied on |
Awesome, thanks for the detailed report, repro and proposed fix :) I'll properly check on it soon! |
When processing text character by character, it's better to use the use unicode_segmentation::UnicodeSegmentation;
use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
fn main() {
let s = "🙂↕️"; // U+1F642 U+200D U+2195 U+FE0F head shaking vertically
println!("{:?}", s.chars().map(|c| c.width().unwrap()).collect::<Vec<usize>>()); // => [2, 0, 1, 0]
println!("{:?}", s.graphemes(true).map(|g| g.width()).collect::<Vec<usize>>()); // => [2]
} |
Nevermind. There's still an off-by-one error somewhere in the algorithm in #171. Gotta debug tomorrow. Feel free to take a stab at it if you finde the time and mindset :D |
Patch is released :) |
Describe the bug
comfy-table panics when rendering a dynamically-arranged non-ASCII content in a narrow cell.
Steps to reproduce
Complete setup: https://gitlab.com/uasi/20250117-comfy-table-panic
Logs (if applicable)
Operating system
macOS 15.2
Comfy-table version
v7.1.3
Additional context
Related issue #53
himalaya is affected by this bug pimalaya/himalaya#497
The text was updated successfully, but these errors were encountered: