Skip to content

Commit

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

The solution consisted to count the number of characters present
 in the input instead of the input length.
  • Loading branch information
pythonbrad authored Sep 18, 2024
1 parent fd6812e commit 4d5af8f
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);

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

0 comments on commit 4d5af8f

Please sign in to comment.