Skip to content

Cherry-pick #50 + add regression tests for richText shared-string dedup#66

Merged
protobi-pieter merged 2 commits into
masterfrom
fix/pr50-richtext-shared-strings
May 7, 2026
Merged

Cherry-pick #50 + add regression tests for richText shared-string dedup#66
protobi-pieter merged 2 commits into
masterfrom
fix/pr50-richtext-shared-strings

Conversation

@protobi-pieter

@protobi-pieter protobi-pieter commented May 7, 2026

Copy link
Copy Markdown

Summary

Cherry-picks protobi/exceljs#50 by @gwkline and adds the regression tests it was missing.

The bug: SharedStrings.add() used value directly as a hash key. For richText values (objects with a richText array), JavaScript coerces the object to the string "[object Object]", so every richText cell deduped into a single shared-string entry — corrupting the workbook's strings table.

The fix (cherry-picked): When the value is a richText object, hash by its rendered XML representation instead. Plain strings are unchanged.

This PR also adds unit tests covering:

  1. Two equal richText values share one entry; a different one gets its own
  2. richText values that differ only in formatting (e.g. plain vs bold) are NOT deduped

Without these tests, the bug could silently regress.

Upstream context

This bug was first reported as exceljs/exceljs#2267 (May 2023, @techiesalman). An alternative fix was opened upstream as exceljs/exceljs#2588 (Nov 2023, @PetrChalov) but has been stale since Feb 2024. @gwkline rediscovered the bug independently and submitted a different fix to the protobi fork. The regression tests added in this PR cover both fix approaches.

Files changed

Test plan

npm run test:unit
# 4 passing in SharedStrings (was 2 before this PR)

Confirmed the new tests fail without the cherry-picked fix:

✗ Deduplicates richText values by their XML representation
  AssertionError: expected +0 to not equal +0
✗ Distinguishes richText entries that differ only in formatting
  AssertionError: expected +0 to not equal +0

These failures are exactly the regression: every richText collapses to index 0.

Related to source code

gwkline and others added 2 commits May 6, 2026 22:52
Covers the bug fixed in the cherry-picked commit: richText objects
previously collapsed to hash key '[object Object]', deduping every
richText cell into a single shared-string entry. Tests verify both
correct deduplication and distinction by formatting.
@protobi-pieter protobi-pieter changed the title Cherry-pick upstream #50 + add regression tests for richText shared-string dedup Cherry-pick #50 + add regression tests for richText shared-string dedup May 7, 2026
@protobi-pieter
protobi-pieter merged commit 3f0bfdc into master May 7, 2026
3 checks passed
@protobi-pieter
protobi-pieter deleted the fix/pr50-richtext-shared-strings branch May 7, 2026 03:37
protobi-pieter added a commit that referenced this pull request May 7, 2026
Fixes critical bug in WorkbookWriter streaming with useSharedStrings:
every richText cell collapsed into a single shared-string entry
(richText objects coerced to '[object Object]' as hash key, deduping
all of them).

Cherry-picked from #50 by @gwkline; adds regression tests covering
richText deduplication and formatting-aware distinction. Addresses
upstream exceljs#2267.

Also pins uuid to ^9.0.1 to keep browserify build working
(uuid@14 dropped the main field; uuid@11 ships ES2021 syntax that
browserify@16 cannot parse).

Adds AGENTS.md with hard rules for AI-generated PRs.

Files changed:
- lib/utils/shared-strings.js: hash richText by rendered XML
- spec/unit/utils/shared-strings.spec.js: 2 new regression tests
- AGENTS.md: new (hard rules for AI agents)
- README.md, CONTRIBUTING.md: pointers to AGENTS.md, release notes
- .github/PULL_REQUEST_TEMPLATE.md: per-PR checklist
- FORK.md: release notes
- package.json, package-lock.json: version bump, uuid 8 -> 9

Tests: 886 unit tests passing (4 in SharedStrings, up from 2).

PRs: #64 (uuid), #65 (AGENTS.md), #66 (richText fix)
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.

2 participants