Skip to content

Commit

Permalink
Fix crash parsing an empty multi-text that contains an empty span (#1338
Browse files Browse the repository at this point in the history
)

- This bug caused a crash importing into FieldWorks
  • Loading branch information
jasonleenaylor authored Aug 12, 2024
1 parent 269c813 commit d85edaa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion SIL.Lift.Tests/Parsing/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using SIL.Lift.Parsing;
using SIL.Lift.Tests.Properties;
using SIL.Lift.Validation;
using SIL.TestUtilities;
using Unit = NUnit.Framework;
using Has = NMock2.Has;
using Is = NMock2.Is;

Expand Down Expand Up @@ -160,6 +160,23 @@ public void MultiTextWithNestedSpan()
Assert.AreEqual(0, subspan.Spans.Count);
}

[Test]
public void MultiTextWithEmptyNestedSpan()
{
_doc.LoadXml("<foobar><form lang='x'><text><span lang='y'></span></text></form></foobar>");
_parser.ParsingWarning += (sender, args) => { Assert.Fail("Could not parse empty span in an empty multitext.");};
var t = _parser.ReadMultiText(_doc.FirstChild);
var tx = t["x"];
Assert.That(tx, Unit.Is.Not.Null);
Assert.That(tx.Text, Unit.Is.Null);
Assert.That(tx.Spans.Count, Unit.Is.EqualTo(1));
var span = tx.Spans[0];
Assert.That(span, Unit.Is.Not.Null);
Assert.That(span.Class, Unit.Is.Null);
Assert.That(span.Lang, Unit.Is.EqualTo("y"));
Assert.That(span.Length, Unit.Is.EqualTo(0));
}

[Test]
public void FirstValueOfSimpleMultiText()
{
Expand Down
2 changes: 1 addition & 1 deletion SIL.Lift/Parsing/LiftMultiText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public LiftSpan AddSpan(string key, string lang, string style, string href, int
alternative = new LiftString();
this[key] = alternative;
}
int start = alternative.Text.Length;
int start = alternative.Text?.Length ?? 0;
if (lang == key)
lang = null;
var span = new LiftSpan(start, length, lang, style, href);
Expand Down

0 comments on commit d85edaa

Please sign in to comment.