Skip to content

Fix UnicodeMapper's trimming of some whitespace that should be preserved - #248

Merged
stesee merged 2 commits into
Codeuctivity:mainfrom
opendocx:fix/unicode-xml-whitespace-upstream
Oct 24, 2026
Merged

stesee merged 2 commits into
Codeuctivity:mainfrom
opendocx:fix/unicode-xml-whitespace-upstream

Conversation

@lowellstewart

Copy link
Copy Markdown

Word retains NBSP and other Unicode whitespace at the boundaries of w:t elements without xml:space="preserve". UnicodeMapper currently uses the general Unicode Trim(), deleting these characters. Split-run text can consequently lose a separator, and mapper round trips or regex replacements can lose text or matches.

Limit boundary trimming to XML whitespace: space, tab, CR, and LF. Existing internal line-ending/tab normalization and preservation behavior stay the same.

Keep the original 107-case Word comparison and add 43 synthetic cases opened and saved by Word for Mac 16.114. The additional fixture covers Unicode whitespace, absent/default/preserve settings, split runs, standalone NBSP, and referenced CR/CRLF. Include reviewable source XML and reproduction/provenance notes. Also test NBSP mapper round trips and repeated split-run replacements with surrounding text.

Validation on Codeuctivity main at 0d55d75 plus only these two commits:

  • Expanded regression checks fail before the fix and pass after it.
  • Full Release solution build passes.
  • Full test suite: 806 passed, 0 failed, 1 existing skip.

The change introduces no dependency, namespace, or target-framework changes. All added DOCX fixtures are synthetic.

@lowellstewart
lowellstewart requested a review from stesee as a code owner October 21, 2026 22:02
ReadOnlySpan<char> span = preserve
? text.AsSpan()
: text.AsSpan().Trim();
: text.AsSpan().Trim(" \t\r\n");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you thought about other spots that may need the same fix?

@stesee
stesee merged commit 25f9b61 into Codeuctivity:main Oct 24, 2026
1 check passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants