fix(html): do not crash ConvertToHtml when StyleDefinitionsPart is missing#266
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
word/styles.xml(StyleDefinitionsPart) is optional in OOXML — Word opens a document-only package without repair — butFormattingAssembler.AssembleFormattingdereferenced 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.cscallsAssembleFormattingat line 904, the tab-stop code at 907). So a package with onlyword/document.xmlstill threwArgumentNullException("part")before producing any HTML.AssembleFormattingentry via a new sharedStyleFactory.EnsureStylesPartfind-or-create helper (extracted from the two identical synthesize sitesStyleFactoryalready had), synthesizing an emptyw:stylesroot so every style lookup falls through to built-in defaults. One place covers the full-document,RenderBlockHtml, and session-render paths — plus any directFormattingAssemblercaller (MetricsGetter,WmlToXml, the WASM converter).ClearStyleswrites the styles part back), so guards can't cover it.AssembleFormattingalready mutates the document in place throughout, so materializing the part is consistent with its contract.HCO062converts 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
styles.xml(e.g. document-only)Test plan
HCO062— programmatic document-only package converts (fails on main with the exact reported exception)HCO063— in-repoTestFiles/RPR-FivePageTestDoc.docxdocument-only fixture converts (previously crashed)HCO064—RenderBlockHtmlon a styles-less sourceCloses #265