Skip to content

Panic when slice Chinese process name #176

@zxlzy

Description

@zxlzy

Each Chinese character has three bytes. So your code in table.rs will cause a panic.

fn truncate_middle(row: &str, max_length: u16) -> String {
    if row.len() as u16 > max_length {
        let first_slice = &row[0..(max_length as usize / 2) - 2];
        let second_slice = &row[(row.len() - (max_length / 2) as usize + 2)..row.len()];
        format!("{}[..]{}", first_slice, second_slice)
    } else {
        row.to_string()
    }
}

like that:

let s = "中文";
let s = &s[0..2];

panicked at 'byte index 2 is not a char boundary; it is inside '中' (bytes 0..3) of 中文

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions