Skip to content

Commit

Permalink
fix(translator): fix problem with the input length
Browse files Browse the repository at this point in the history
This commit fix the problem of panick when the input contains
 a character who has a length >= 2.

The solution consisted to use the number of characters present
 in the input instead of the input length.
  • Loading branch information
pythonbrad committed Sep 18, 2024
1 parent fd6812e commit 258d12f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion engine/translator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ impl Translator {
#[cfg(feature = "rhai")]
let engine = Engine::new();
let predicates = self.dictionary.iter().filter_map(|(key, values)| {
if input.len() < 2 || input.len() > key.len() || key[0..1] != input[0..1] {
if input.chars().count() < 2 || input.len() > key.len() || key[0..1] != input[0..1] {
return None;
};

Expand Down Expand Up @@ -452,6 +452,8 @@ mod tests {
#[cfg(feature = "rhai")]
let mut translator = Translator::new(dictionary, true);

//
translator.translate("ù");
//
#[cfg(feature = "rhai")]
{
Expand Down

0 comments on commit 258d12f

Please sign in to comment.