chiark / gitweb /
Fix character counting in masked passwords.
authorSimon Tatham <anakin@pobox.com>
Sat, 3 Feb 2024 12:06:04 +0000 (12:06 +0000)
committerSimon Tatham <anakin@pobox.com>
Sat, 3 Feb 2024 12:06:04 +0000 (12:06 +0000)
Thanks to Ian for picking this out of Clippy's huge output dump: when
counting the things in a str that EditorCore would regard as
characters, we were using 'map' rather than 'filter' to pick out
things with positive terminal width, which had no effect on the
following .count(). So a Unicode combining character would display an
extra * in the masked password when _not_ editing it, compared to when
editing it.

src/editor.rs

index 2d6a28e30295554d1bfbd398e56e2a11434df888..6670d9b5096c256cd102eb184f1d559797c56982 100644 (file)
@@ -839,7 +839,7 @@ pub struct EditableMenuLine<Data: EditableMenuLineData> {
 
 pub fn count_edit_chars(text: &str) -> usize {
     text.chars()
-        .map(|c| UnicodeWidthChar::width(c).unwrap_or(0) > 0)
+        .filter(|c| UnicodeWidthChar::width(*c).unwrap_or(0) > 0)
         .count()
 }