From 61cecb7af5e787657817fa4182c0d7ebc4ea8ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Hatcher?= Date: Sun, 28 Sep 2025 12:27:03 +0200 Subject: [PATCH] FIX: Fixes case with unicode characters This is an ugly bug in ugly code. Pretty much technical deb in here --- xlsx/src/import/worksheets.rs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/xlsx/src/import/worksheets.rs b/xlsx/src/import/worksheets.rs index 9469d65..fc60783 100644 --- a/xlsx/src/import/worksheets.rs +++ b/xlsx/src/import/worksheets.rs @@ -264,30 +264,29 @@ enum ParseReferenceError { // There is a similar named function in ironcalc_base. We probably should fix both at the same time. // NB: Maybe use regexes for this? fn parse_reference(s: &str) -> Result { - let bytes = s.as_bytes(); let mut sheet_name = "".to_string(); let mut column = "".to_string(); let mut row = "".to_string(); let mut state = "sheet"; // "sheet", "col", "row" - for &byte in bytes { + for ch in s.chars() { match state { "sheet" => { - if byte == b'!' { + if ch == '!' { state = "col" } else { - sheet_name.push(byte as char); + sheet_name.push(ch); } } "col" => { - if byte.is_ascii_alphabetic() { - column.push(byte as char); + if ch.is_ascii_alphabetic() { + column.push(ch); } else { state = "row"; - row.push(byte as char); + row.push(ch); } } _ => { - row.push(byte as char); + row.push(ch); } } } @@ -1122,3 +1121,16 @@ pub(super) fn load_sheets( } Ok((sheets, selected_sheet)) } + +#[cfg(test)] +mod tests { + use crate::import::worksheets::parse_reference; + + #[test] + fn parse_reference_works() { + let cell_reference = parse_reference("📈 Overview!B2"); + assert!(cell_reference.is_ok()); + let cell_reference = cell_reference.unwrap(); + assert_eq!(cell_reference.sheet, "📈 Overview"); + } +}