diff --git a/Src/LexText/Interlinear/BIRDInterlinearImporter.cs b/Src/LexText/Interlinear/BIRDInterlinearImporter.cs index b36b2b9956..9275ec6b99 100644 --- a/Src/LexText/Interlinear/BIRDInterlinearImporter.cs +++ b/Src/LexText/Interlinear/BIRDInterlinearImporter.cs @@ -728,6 +728,8 @@ private static IAnalysis CreateWordAnalysisStack(LcmCache cache, Word word) foreach (var wordItem in word.Items) { + if (wordItem.Value == null) + continue; ITsString wordForm = null; switch (wordItem.type) { @@ -758,7 +760,8 @@ private static IAnalysis CreateWordAnalysisStack(LcmCache cache, Word word) } else { - Debug.Assert(analysis != null, "What else could this do?"); + // There was an invalid analysis in the file. We can't do anything with it. + return null; } // Fill in morphemes, lex. entries, lex. gloss, and lex.gram.info diff --git a/Src/LexText/Interlinear/ITextDllTests/BIRDFormatImportTests.cs b/Src/LexText/Interlinear/ITextDllTests/BIRDFormatImportTests.cs index 7ffe441136..b361a988fb 100644 --- a/Src/LexText/Interlinear/ITextDllTests/BIRDFormatImportTests.cs +++ b/Src/LexText/Interlinear/ITextDllTests/BIRDFormatImportTests.cs @@ -449,6 +449,77 @@ public void UglyEmptyDataShouldNotCrash() } } + [Test] + public void EmptyTxtItemUnderWordShouldNotCrash() + { + // an interlinear text example xml string + const string xml = +"" + +"" + +"" + +"Test" + +"" + +"" + +"" + +"" + +"testing paragraph without words" + +"" + +"" + +"" + // empty txt item +"" + +"" + +"In the country of a Mongol king lived three sisters." + +"" + +"" + +"This is a test." + +"1" + +"" + +"" + +"This" + +"" + +"" + +"is" + +"" + +"" + +"a" + +"" + +"" + +"test" + +"" + +"" + +"." + +"" + +"" + +"" + +"" + +"" + +"" + +"" + +"" + +"" + +"" + +"" + +"" + +""; + + var li = new LinguaLinksImport(Cache, null, null); + LCModel.IText text = null; + using(var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray()))) + { + // SUT - Verify that no crash occurs importing this data: see LT-22008 + Assert.DoesNotThrow(()=> li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text)); + using(var firstEntry = Cache.LanguageProject.Texts.GetEnumerator()) + { + firstEntry.MoveNext(); + var imported = firstEntry.Current; + Assert.That(imported.ContentsOA.ParagraphsOS.Count, Is.EqualTo(1)); + Assert.That(((IStTxtPara)imported.ContentsOA.ParagraphsOS[0]).SegmentsOS.Count, Is.EqualTo(2)); + // Verify that the words with non-empty txt were imported + Assert.That(((IStTxtPara)imported.ContentsOA.ParagraphsOS[0]).SegmentsOS[1].AnalysesRS.Count, Is.EqualTo(5)); + } + } + } + [Test] public void TestImportMergeFlexTextWithSegnumItem() {