Skip to content

fix(html): do not crash ConvertToHtml when StyleDefinitionsPart is missing#266

Merged
JSv4 merged 1 commit into
mainfrom
fix/html-missing-styles-part
Jul 12, 2026
Merged

fix(html): do not crash ConvertToHtml when StyleDefinitionsPart is missing#266
JSv4 merged 1 commit into
mainfrom
fix/html-missing-styles-part

Conversation

@JSv4

@JSv4 JSv4 commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • word/styles.xml (StyleDefinitionsPart) is optional in OOXML — Word opens a document-only package without repair — but FormattingAssembler.AssembleFormatting dereferenced it unconditionally at many sites, and it runs before the settings read fixed in fix(html): do not crash ConvertToHtml when DocumentSettingsPart is missing #264 (WmlToHtmlConverter.cs calls AssembleFormatting at line 904, the tab-stop code at 907). So a package with only word/document.xml still threw ArgumentNullException("part") before producing any HTML.
  • Fix: ensure the styles part exists at the AssembleFormatting entry via a new shared StyleFactory.EnsureStylesPart find-or-create helper (extracted from the two identical synthesize sites StyleFactory already had), synthesizing an empty w:styles root so every style lookup falls through to built-in defaults. One place covers the full-document, RenderBlockHtml, and session-render paths — plus any direct FormattingAssembler caller (MetricsGetter, WmlToXml, the WASM converter).
  • Why not per-site null-guards (the fix(html): do not crash ConvertToHtml when DocumentSettingsPart is missing #264 approach): fix(html): do not crash ConvertToHtml when DocumentSettingsPart is missing #264 had exactly one read site; here there are ~9 scattered reads and a write (ClearStyles writes the styles part back), so guards can't cover it. AssembleFormatting already mutates the document in place throughout, so materializing the part is consistent with its contract.
  • The rest of the pipeline tolerates every absent optional part: HCO062 converts a package with no optional parts at all (no styles, settings, theme, font table, numbering) end to end, which settles the audit item from ConvertToHtml throws ArgumentNullException("part") when styles.xml (StyleDefinitionsPart) is missing — sibling of #264 #265.

Behaviour

Package shape Before After
styles present OK unchanged
no styles.xml (e.g. document-only) crash built-in defaults, HTML produced

Test plan

  • HCO062 — programmatic document-only package converts (fails on main with the exact reported exception)
  • HCO063 — in-repo TestFiles/RPR-FivePageTestDoc.docx document-only fixture converts (previously crashed)
  • HCO064RenderBlockHtml on a styles-less source
  • Full suite: 2669 passed / 0 failed / 3 skipped
  • Release build: 0 errors (warning count unchanged from main)

Closes #265

…ssing

word/styles.xml is optional in OOXML (Word opens a document-only package
without repair), but FormattingAssembler.AssembleFormatting dereferenced
StyleDefinitionsPart unconditionally at many sites - and it runs before
the settings fix from #264 - so a package with only word/document.xml
still threw ArgumentNullException("part") before producing any HTML.

Ensure the styles part exists at the AssembleFormatting entry via a new
shared StyleFactory.EnsureStylesPart find-or-create helper (extracted
from the two identical synthesize sites already in StyleFactory), so
every style lookup falls through to built-in defaults; this covers the
full-document, RenderBlockHtml, and session-render paths in one place.

Regression coverage: HCO062 (programmatic document-only package), HCO063
(in-repo RPR-FivePageTestDoc.docx document-only fixture), HCO064
(RenderBlockHtml on a styles-less source).

Closes #265
@JSv4
JSv4 merged commit bf5c498 into main Jul 12, 2026
12 checks passed
@JSv4
JSv4 deleted the fix/html-missing-styles-part branch July 12, 2026 02:05
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.

ConvertToHtml throws ArgumentNullException("part") when styles.xml (StyleDefinitionsPart) is missing — sibling of #264

1 participant