Skip to content

fix(converter): handle null rPr in DefineRunStyle and GetLangAttribute#81

Merged
JSv4 merged 1 commit intomainfrom
fix/null-rpr-handling
Dec 19, 2025
Merged

fix(converter): handle null rPr in DefineRunStyle and GetLangAttribute#81
JSv4 merged 1 commit intomainfrom
fix/null-rpr-handling

Conversation

@JSv4
Copy link
Copy Markdown
Owner

@JSv4 JSv4 commented Dec 19, 2025

Summary

  • Fixed InvalidOperationException crash in DefineRunStyle and GetLangAttribute when converting runs without w:rPr elements
  • Changed .First() to .FirstOrDefault() with null checks to handle runs that have no explicit run properties gracefully

Problem

Previously, two methods in WmlToHtmlConverter.cs used .First() on run.Elements(W.rPr):

  • DefineRunStyle (line 4827)
  • GetLangAttribute (line 4979)

This would crash with InvalidOperationException: Sequence contains no elements if a run had no w:rPr element.

Solution

  • Changed .First() to .FirstOrDefault() with null checks
  • DefineRunStyle returns empty style dictionary when rPr is null
  • GetLangAttribute returns null when rPr is null

Test plan

  • Added test HC016_RunWithoutRPr_DoesNotCrash that creates a document with runs lacking w:rPr elements and verifies conversion succeeds
  • All 75 HTML converter tests pass
  • Updated documentation in wml_to_html_converter_gaps.md to mark issue as resolved
  • Added changelog entry

Previously, DefineRunStyle and GetLangAttribute in WmlToHtmlConverter
used .First() on run.Elements(W.rPr), which would crash with
InvalidOperationException if a run had no explicit run properties.

This change:
- Changes .First() to .FirstOrDefault() with null checks
- Returns empty style dictionary from DefineRunStyle when rPr is null
- Returns null from GetLangAttribute when rPr is null

Added test HC016_RunWithoutRPr_DoesNotCrash that creates a document
with runs lacking w:rPr elements and verifies conversion succeeds.

Updated documentation to mark this gap as resolved.
@JSv4 JSv4 merged commit ed9db90 into main Dec 19, 2025
6 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