diced / dlauncher

An application launcher for Linux that is based on Ulauncher
GNU General Public License v3.0
81 stars 6 forks source link

Fix `ResultWidget::new` when `entry` is unicode #7

Closed Diegovsky closed 2 years ago

Diegovsky commented 2 years ago

Error

thread 'main' panicked at 'byte index 18 is not a char boundary; it is inside 'õ' (bytes 17..19) of `Editor de partições GParted`'

Explanation

This happens because of "raw" string indexing in src/launcher/result.rs:40 (74d8e30):

    let mut name_c = entry.name().to_string();
    for (_, (index, chars)) in match_.0.iter().rev().enumerate() {
      // Here
      name_c = name_c[0..*index].to_string().to_string()
        + &open_tag
        + &chars
        + close_tag
        // Here too
        + &name_c[index + chars.len()..];
    }

Since string in rust are internally UTF-8 encoded, it's fine to index them in ascii-only environments, however it panics if the index is in a unicode char boundry.

Fix

I exported fuzzy::utils::slice_utf8 since it's already there and it worked great :)

Also, just a suggestion: since you grabbed a some functions from fuzzywuzzy, you should consider outright depending on it as rustc is smart enough to remove functions not in use.

diced commented 2 years ago

Also, just a suggestion: since you grabbed a some functions from fuzzywuzzy, you should consider outright depending on it as rustc is smart enough to remove functions not in use.

Ah, that totally crossed my mind when I was doing that. I'll consider doing that soon then.

PR looks good also.

Diegovsky commented 2 years ago

Thank you so much!