From 4d725e6bc14c7fe1b4473a9314ec2049afb9692d Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:24:46 -0500 Subject: [PATCH 1/2] Reject Unicode noncharacters in UNICHAR --- crates/functions/src/text.rs | 13 ++++++++++++- docs/function-parity.md | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/functions/src/text.rs b/crates/functions/src/text.rs index df125f022..0993141be 100644 --- a/crates/functions/src/text.rs +++ b/crates/functions/src/text.rs @@ -281,7 +281,11 @@ fn unichar(a: &[Arg], _c: &mut dyn Ctx) -> R { if !(1.0..=1_114_111.0).contains(&n) { return Err(CellError::Value); } - match char::from_u32(n as u32) { + let cp = n as u32; + if (0xFDD0..=0xFDEF).contains(&cp) || cp & 0xFFFE == 0xFFFE { + return Err(CellError::NA); + } + match char::from_u32(cp) { Some(c) => text_val(c.to_string()), None => Err(CellError::NA), } @@ -1181,8 +1185,15 @@ mod tests { close(ev("CODE", vec![t("€")]), 128.0); is_err(ev("CODE", vec![t("")]), CellError::Value); is_text(ev("UNICHAR", vec![n(9731.0)]), "☃"); + for cp in [0xFDD0, 0xFDEF, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF, 0x10FFFE, 0x10FFFF] { + is_err(ev("UNICHAR", vec![n(f64::from(cp))]), CellError::NA); + } + for cp in [0xFDCF, 0xFDF0, 0xFFFD, 0x1FFFD] { + assert!(matches!(ev("UNICHAR", vec![n(f64::from(cp))]), Value::Text(_))); + } close(ev("UNICODE", vec![t("☃")]), 9731.0); is_err(ev("UNICHAR", vec![n(0.0)]), CellError::Value); + is_err(ev("UNICHAR", vec![n(1_114_112.0)]), CellError::Value); is_err(ev("UNICHAR", vec![n(55296.0)]), CellError::NA); } diff --git a/docs/function-parity.md b/docs/function-parity.md index d9823e8bf..de70ab192 100644 --- a/docs/function-parity.md +++ b/docs/function-parity.md @@ -1,6 +1,6 @@ # Function parity: worksheet functions and formulas -> **Last reviewed:** 2026-10-15 · **Last updated:** 2026-10-27 · **Change:** minor (ECMA.CEILING listed with USDOLLAR as not on Microsoft's list; earlier: IMSQRT reproduces the stray real part Excel gives for negative reals, and the other IM* differences from Excel are listed; earlier: the LAMBDA row lists the recursion limit and its `#NUM!`, and the error a defined name holding an error gives when called; earlier: number text with accounting parentheses coerces like Excel 365; INDEX with one index on a 2-D reference is #REF! as in Excel; earlier: SUBTOTAL and AGGREGATE cap the cells they visit, #2175) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 +> **Last reviewed:** 2026-10-31 · **Last updated:** 2026-10-31 · **Change:** minor (UNICHAR returns `#N/A` for Unicode noncharacters, as observed in Excel; earlier: ECMA.CEILING listed with USDOLLAR as not on Microsoft's list; IMSQRT reproduces Excel's stray real part for negative reals) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 Excel's worksheet functions, category by category, against GridCraft's function library. Part of [target-app-parity.md](target-app-parity.md); gaps feed [gaps.md](gaps.md). @@ -29,6 +29,8 @@ Excel's worksheet functions, category by category, against GridCraft's function ## Coverage +| 2026-10-31 | minor | UNICHAR returns `#N/A` for U+FDD0–U+FDEF and U+FFFE/U+FFFF on every plane; adjacent valid characters and existing invalid-range/surrogate errors remain unchanged, matching Excel | + **Measured: 513 / 523 by name (98.1%); 504 / 523 working (96.4%).** | Category | Excel | Ours | Working | % working | Missing | From 5ee65a8005c1fb603aab5f35758f70f58ae2a8e5 Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:35:50 -0500 Subject: [PATCH 2/2] Tighten UNICHAR regressions and parity history --- crates/functions/src/text.rs | 4 ++-- docs/function-parity.md | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/functions/src/text.rs b/crates/functions/src/text.rs index 0993141be..1e789d0aa 100644 --- a/crates/functions/src/text.rs +++ b/crates/functions/src/text.rs @@ -1188,8 +1188,8 @@ mod tests { for cp in [0xFDD0, 0xFDEF, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF, 0x10FFFE, 0x10FFFF] { is_err(ev("UNICHAR", vec![n(f64::from(cp))]), CellError::NA); } - for cp in [0xFDCF, 0xFDF0, 0xFFFD, 0x1FFFD] { - assert!(matches!(ev("UNICHAR", vec![n(f64::from(cp))]), Value::Text(_))); + for (cp, expected) in [(0xFDCF, "\u{FDCF}"), (0xFDF0, "\u{FDF0}"), (0xFFFD, "\u{FFFD}"), (0x1FFFD, "\u{1FFFD}")] { + is_text(ev("UNICHAR", vec![n(f64::from(cp))]), expected); } close(ev("UNICODE", vec![t("☃")]), 9731.0); is_err(ev("UNICHAR", vec![n(0.0)]), CellError::Value); diff --git a/docs/function-parity.md b/docs/function-parity.md index de70ab192..22827766b 100644 --- a/docs/function-parity.md +++ b/docs/function-parity.md @@ -29,8 +29,6 @@ Excel's worksheet functions, category by category, against GridCraft's function ## Coverage -| 2026-10-31 | minor | UNICHAR returns `#N/A` for U+FDD0–U+FDEF and U+FFFE/U+FFFF on every plane; adjacent valid characters and existing invalid-range/surrogate errors remain unchanged, matching Excel | - **Measured: 513 / 523 by name (98.1%); 504 / 523 working (96.4%).** | Category | Excel | Ours | Working | % working | Missing | @@ -126,6 +124,7 @@ workbooks; results checked in as data, not Excel files) and fixing what it finds | Date | Change | Summary | |---|---|---| +| 2026-10-31 | minor | UNICHAR returns `#N/A` for U+FDD0–U+FDEF and U+FFFE/U+FFFF on every plane; adjacent valid characters and existing invalid-range/surrogate errors remain unchanged, matching Excel | | 2026-10-27 | minor | ECMA.CEILING added to the functions that are in our library but not on Microsoft's list (with USDOLLAR), so the counts don't change | | 2026-10-26 | minor | IMSQRT uses Excel's polar route with its cosine reduction, so `IMSQRT("-4")` is `1.22514845490862E-16+2i` as in Excel (exact `2i` before); the rows list the IM* differences still open | | 2026-10-25 | minor | LAMBDA row: a LAMBDA that calls itself more than 140 times, and a formula nested past the depth limit, give `#NUM!` (#1809; nesting gave `#CALC!` before). `=Foo(1)` where the defined name Foo holds `#N/A` gives `#N/A`, not `#NAME?` |