Fix NRE in XLiffBody.AddTransUnit when tu.Source is null#153
Open
imnasnainaec wants to merge 9 commits into
Open
Fix NRE in XLiffBody.AddTransUnit when tu.Source is null#153imnasnainaec wants to merge 9 commits into
imnasnainaec wants to merge 9 commits into
Conversation
A malformed baseline XLIFF can contain a trans-unit with no source variant, causing a NullReferenceException when MergeXliffDocuments compares it against the current scan. Use null-conditional access so a null old source is simply treated as differing from the new source. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
When the baseline trans-unit's source is null/whitespace, the unit is still counted as changed, but skip the OLD TEXT note since it would carry no value. Uses IsNullOrWhiteSpace to match other XLiffUtils source-value checks. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Collapse the Target/Source null guards in AddTransUnit, NumberTranslated, and NumberApproved to use ?. access. In the NumberTranslated 'differs from source' heuristic, also require a non-blank source (IsNullOrWhiteSpace) so a blank source no longer trivially counts a unit as translated. AddTransUnit keeps != null since an empty/whitespace value is still a legitimate stored translation. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
tu.SourceinAddTransUnitso a null Source doesn't throw when Target is also nulltu.Sourcein theNumberTranslatedproperty for the same casetu.Source/tuOld.SourceinMergeXliffDocumentsagainst the same NRE when a baseline XLIFF unit has no source variant; a blank old source is still counted as changed but no longer emits an emptyOLD TEXTnoteAddTransUnit,NumberTranslated, andNumberApprovedto use null-conditional (?.) access. As part of this, theNumberTranslated"differs from source" heuristic now requires a non-blank source (IsNullOrWhiteSpace), so a unit with a blank source no longer trivially counts as translated.AddTransUnitkeeps!= nullsince an empty/whitespace value is still a legitimate stored translation.Closes #149
Devin review: https://app.devin.ai/review/sillsdev/l10nsharp/pull/153
This change is