Skip to content

JSE-F5: sheet names count code points, as Excel does - #122

Merged
securedeveloper merged 1 commit into
mainfrom
jse-f5-sheet-names
Nov 17, 2026
Merged

securedeveloper merged 1 commit into
mainfrom
jse-f5-sheet-names

Conversation

@securedeveloper

Copy link
Copy Markdown
Owner

Stacked on #121 (the History confirmation). This branch contains #121's commit, so merge #121 first; this diff then shrinks to the JSE-F5 commit alone.

Excel for Mac accepts a sheet name of 30 × x + 😀, which is 31 code points and 32 UTF-16 units (conformance check, 2026-11-17). validateSheetName counted UTF-16 units (name.length > 31), so the writer threw INVALID_SHEET_NAME for names Excel accepts.

Changes (src/sheet-names.ts)

  • validateSheetName, and therefore the writer, limit a name to 31 code points.
  • sanitizeSheetName cuts long names to 31 code points and never splits a surrogate pair. It still removes an apostrophe the cut leaves at the end.
  • History is unchanged: reserved in any case (Excel refuses it with "History is a reserve word"), and sanitizeSheetName turns it into Sheet. react-data-export's legacy components rely on that: they sanitize, warn, then add (2) suffixes for duplicates.
name before after
30 × x + 😀 (31 cp, 32 units) rejected / sanitized to 30 × x valid, kept
31 × x + 😀 (32 cp) rejected rejected; sanitized to 31 × x
31 × 😀 (31 cp, 62 units) rejected valid
History, history, HISTORY reserved → Sheet unchanged

Tests

test/write/writer-features.test.ts: the cases above, truncation, the trailing apostrophe after a cut, and the writer end to end (it accepts 30 x + 😀 and rejects one more). The existing sanitize test's expectation for 30 x + 😀 changes from xxx…x to the name kept as is. Full suite: 949 pass.

docs/api.md §3.3 and the sanitizeSheetName signature comment are updated. Patch changeset.

Excel for Mac accepts a sheet name of 30 x's and an emoji: 31 code
points, 32 UTF-16 units (conformance check, 2026-11-17). The validator
counted UTF-16 units (name.length > 31), so the writer rejected names
Excel accepts.

- validateSheetName (and so the writer) counts code points.
- sanitizeSheetName cuts to 31 code points, never splitting a surrogate
  pair, and still drops an apostrophe the cut leaves at the end.
- History stays reserved in any case; sanitize turns it into "Sheet",
  which react-data-export's legacy components rely on.
- Tests: 30 x + emoji accepted, 31 x + emoji rejected, 31 and 32
  emoji, truncation, the writer end to end.
@securedeveloper
securedeveloper merged commit e872fd5 into main Nov 17, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant