Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [L10NSharp.Windows.Forms] Restored project-local Resources support for `FallbackLanguagesDlgBase` button images (`Move`, `Move_up`, and `Move_down`).
- [L10NSharp.Windows.Forms] Corrected resource manager base name to `L10NSharp.Windows.Forms.Properties.Resources`.
- [L10NSharp.Windows.Forms.Tests] Corrected resource manager base name to `L10NSharp.Windows.Forms.Tests.Properties.Resources`.
- [L10NSharp] Fixed `NullReferenceException` in `XLiffBody.AddTransUnit` when a trans-unit has no source variant (e.g. from a malformed XLIFF file). (#149)

### Removed

Expand Down
8 changes: 8 additions & 0 deletions src/L10NSharp.Tests/XLiffLocalizationManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ public void MergeXliffDocuments_WorksAsExpected()
}, true);
}

[Test]
public void AddTransUnit_NullSourceNullTarget_DoesNotThrow()
{
var body = new XLiffBody();
var tu = new XLiffTransUnit { Id = "some-id", Source = null, Target = null };
Assert.DoesNotThrow(() => body.AddTransUnit(tu));
}

private void CheckMergedTransUnit(XLiffTransUnit tu, string sourceText, string[] notes, bool isDynamic)
{
Assert.IsNotNull(tu);
Expand Down
4 changes: 2 additions & 2 deletions src/L10NSharp/XLiffUtils/XLiffBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public bool AddTransUnit(XLiffTransUnit tu)
// the source value there.
if (tu.Target != null && tu.Target.Value != null)
TranslationsById[tu.Id] = tu.Target.Value;
else
else if (tu.Source != null)
TranslationsById[tu.Id] = tu.Source.Value;
return true;
}
Expand Down Expand Up @@ -246,7 +246,7 @@ internal int NumberTranslated
{
++_translatedCount;
}
else if (tu.Target.Value != tu.Source.Value &&
else if (tu.Source != null && tu.Target.Value != tu.Source.Value &&
tu.Target.TargetState == XLiffTransUnitVariant.TranslationState.Undefined)
{
++_translatedCount;
Expand Down
Loading