fix(converter): handle null rPr in DefineRunStyle and GetLangAttribute#81
Merged
fix(converter): handle null rPr in DefineRunStyle and GetLangAttribute#81
Conversation
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.
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
InvalidOperationExceptioncrash inDefineRunStyleandGetLangAttributewhen converting runs withoutw:rPrelements.First()to.FirstOrDefault()with null checks to handle runs that have no explicit run properties gracefullyProblem
Previously, two methods in
WmlToHtmlConverter.csused.First()onrun.Elements(W.rPr):DefineRunStyle(line 4827)GetLangAttribute(line 4979)This would crash with
InvalidOperationException: Sequence contains no elementsif a run had now:rPrelement.Solution
.First()to.FirstOrDefault()with null checksDefineRunStylereturns empty style dictionary whenrPris nullGetLangAttributereturns null whenrPris nullTest plan
HC016_RunWithoutRPr_DoesNotCrashthat creates a document with runs lackingw:rPrelements and verifies conversion succeedswml_to_html_converter_gaps.mdto mark issue as resolved