From ff108df89f4e46ae9d6fb8b951b204849116f884 Mon Sep 17 00:00:00 2001 From: Rolo Date: Thu, 30 May 2024 21:58:47 -0700 Subject: [PATCH] fix(color): off-by-one for `INDEXED_COLORS` access --- src/structs/color.rs | 6 +++--- tests/integration_test.rs | 12 ++++++++++++ tests/test_files/red_indexed_color.xlsx | Bin 0 -> 8058 bytes 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 tests/test_files/red_indexed_color.xlsx diff --git a/src/structs/color.rs b/src/structs/color.rs index 8792ba6b..10f7cf7f 100644 --- a/src/structs/color.rs +++ b/src/structs/color.rs @@ -100,7 +100,7 @@ impl Color { /// In that case, use get_argb_with_theme(&self, theme: &Theme). pub fn get_argb(&self) -> &str { if self.indexed.has_value() { - match INDEXED_COLORS.get(self.indexed.get_value().clone() as usize - 1) { + match INDEXED_COLORS.get(self.indexed.get_value().clone() as usize) { Some(v) => return v, None => {} } @@ -138,7 +138,7 @@ impl Color { let indexed = INDEXED_COLORS.iter().position(|&r| r == argb); match indexed { Some(v) => { - self.indexed.set_value((v + 1) as u32); + self.indexed.set_value(v as u32); self.argb.remove_value(); } None => { @@ -309,7 +309,7 @@ mod tests { let mut obj = Color::default(); obj.set_argb("FFFF8080"); - assert_eq!(obj.get_indexed(), &22); + assert_eq!(obj.get_indexed(), &21); assert_eq!(obj.get_argb(), "FFFF8080"); let mut obj = Color::default(); diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 391e9171..fe2caae2 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -1400,3 +1400,15 @@ fn issue_188() { let path = std::path::Path::new("./tests/result_files/issue_188.xlsx"); let _ = umya_spreadsheet::writer::xlsx::write(&book, path); } + +#[test] +fn expect_red_indexed_color() { + let path = std::path::Path::new("./tests/test_files/red_indexed_color.xlsx"); + let book = umya_spreadsheet::reader::xlsx::read(path).unwrap(); + + let cell = book.get_sheet(&0).unwrap().get_cell("A1").unwrap(); + + let color = cell.get_style().get_font().unwrap().get_color().get_argb(); + + assert_eq!("FFFF0000", color); +} diff --git a/tests/test_files/red_indexed_color.xlsx b/tests/test_files/red_indexed_color.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..189c157be24088cb3e4b0f1c7c0116dcdcb70e54 GIT binary patch literal 8058 zcmb_h1yodB*G6gSZiFEuXFxzghLjpwx*cKY8O9m9JETECq)Q1A5CjD26huN$0YMr8 zk&sXj_y^xm`F+3d|JL{4weFp`>)Ge*eV%>xzR%TB$Ht+?`r}~7GMUnTnu?2sb$U`^ z{xnl`LAb&Yu2%Y9NEq4z=m~e0mc?Ay++irRg9`!-5C#eX*kA~27aIqJ9T;GsuPi75 zU_-k?5jId~7X%Cp@PeTMvN9K>znfsgfDvdgz~0prDFp(dt?glOC>rR3gds3@Y+X=r zs4M0t$_|8tT024QV4%xFLRUc6e@sKr^>i8l8R=^0S@p}1D=AXcR;@fArW@J1)cu?4-iKr?Dv@OH~s;Haqi4GP$bgX!5Zp{i6ZFq z?mqxgFlY3?K)NGr&IC{J&%gmO$nVzC_6|ri|GyaGrUT+X8^Oia*1;NP<6`Xw$8ZDa z;tbQi=?JrSJ@r8w!wi&z4UCOV2a0mlg2FND0P=JOq3xk4n2nw*3PTh0DUbfEA<;+_ z3~Gb6hrwLo&cI)6|K;gFO~e($I2h>rRrtT2$9FUTZbT0kl+#TY7pMPvw6k7gya&Re z4v2p@0ko@^GwlC8=--Y0%b_t0(LuQ&(U|l_!Txja|041!S`djb1Vgzx!2YK4KP~WS zxW6+4jUgQ-MF0IN{~Gtd?f>6=$K?5c?)sSwgPrbjHZYstL;>`DTb0rIa~mhXY})Kt zFMXaaCtC5?)-X>~0rJ`pT+V$FrU2qdyiX_&Z|tH5gsg10n;Hla^(-s&1Q@Y-mmPb{nCQD~ zr5Wp<;Qs1^NhP{2=sXtID?BVLl0SX;o5$q_aF+=o@?-wgmRHY+jpfz&bQw#o8)-W7 zua~JYS1zUXy6e2HIcct@QVk?qFWm}y2X6NHB$<=N=}|soul)oHxi8T`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