From d2d29fa960e1a85ac14cd983d8d05ccfb4f13010 Mon Sep 17 00:00:00 2001 From: Peter Chapman Date: Thu, 20 Nov 2025 13:28:51 +1300 Subject: [PATCH 1/2] Fix crash when a sidebar is the first element in a book --- .../ScriptureRefUsfmParserHandlerBase.cs | 3 +++ .../Corpora/UsfmMemoryTextTests.cs | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/SIL.Machine/Corpora/ScriptureRefUsfmParserHandlerBase.cs b/src/SIL.Machine/Corpora/ScriptureRefUsfmParserHandlerBase.cs index 9e34968e..696d3968 100644 --- a/src/SIL.Machine/Corpora/ScriptureRefUsfmParserHandlerBase.cs +++ b/src/SIL.Machine/Corpora/ScriptureRefUsfmParserHandlerBase.cs @@ -172,6 +172,9 @@ public override void EndCell(UsfmParserState state, string marker) public override void StartSidebar(UsfmParserState state, string marker, string category) { + if (_curVerseRef.IsDefault) + UpdateVerseRef(state.VerseRef, marker); + StartParentElement(marker); } diff --git a/tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs b/tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs index dfbe8e7d..b710b36c 100644 --- a/tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs +++ b/tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs @@ -131,6 +131,31 @@ public void GetRows_OptBreak_MiddleIncludeMarkers() }); } + [Test] + public void GetRows_Sidebar_FirstTag() + { + TextRow[] rows = GetRows( + @"\id MAT - Test +\esb +\ip My sidebar text +\esbe +\c 1 +\p +\v 1 First verse +", + includeAllText: true, + includeMarkers: true + ); + + Assert.That(rows, Has.Length.EqualTo(3), string.Join(",", rows.Select(tr => tr.Text))); + Assert.That(rows[0].Text, Is.EqualTo("My sidebar text")); + Assert.That(rows[0].Ref, Is.EqualTo(ScriptureRef.Parse("MAT 1:0/1:esb/1:ip"))); + Assert.That(rows[1].Text, Is.Empty); + Assert.That(rows[1].Ref, Is.EqualTo(ScriptureRef.Parse("MAT 1:0/2:p"))); + Assert.That(rows[2].Text, Is.EqualTo("First verse")); + Assert.That(rows[2].Ref, Is.EqualTo(ScriptureRef.Parse("MAT 1:1"))); + } + [Test] public void GetRows_VersePara_BeginningNonVerseSegment() { From 0715464e6e7713c9d7566ede417737d2125268c9 Mon Sep 17 00:00:00 2001 From: Peter Chapman Date: Mon, 24 Nov 2025 08:59:21 +1300 Subject: [PATCH 2/2] Fix crash when a table row is the first element in a book --- .../ScriptureRefUsfmParserHandlerBase.cs | 5 ++++ .../Corpora/UsfmMemoryTextTests.cs | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/SIL.Machine/Corpora/ScriptureRefUsfmParserHandlerBase.cs b/src/SIL.Machine/Corpora/ScriptureRefUsfmParserHandlerBase.cs index 696d3968..063ae48c 100644 --- a/src/SIL.Machine/Corpora/ScriptureRefUsfmParserHandlerBase.cs +++ b/src/SIL.Machine/Corpora/ScriptureRefUsfmParserHandlerBase.cs @@ -143,7 +143,12 @@ public override void EndPara(UsfmParserState state, string marker) public override void StartRow(UsfmParserState state, string marker) { if (CurrentTextType == ScriptureTextType.NonVerse || CurrentTextType == ScriptureTextType.None) + { + if (_curVerseRef.IsDefault) + UpdateVerseRef(state.VerseRef, marker); + StartParentElement(marker); + } } public override void EndRow(UsfmParserState state, string marker) diff --git a/tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs b/tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs index b710b36c..d1321f7c 100644 --- a/tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs +++ b/tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs @@ -156,6 +156,30 @@ public void GetRows_Sidebar_FirstTag() Assert.That(rows[2].Ref, Is.EqualTo(ScriptureRef.Parse("MAT 1:1"))); } + [Test] + public void GetRows_TableRow_FirstTag() + { + TextRow[] rows = GetRows( + @"\id MAT - Test +\tr \th1 Day \th2 Tribe \th3 Leader +\tr \tcr1 1st \tc2 Judah \tc3 Nahshon son of Amminadab +\c 1 +\p +\v 1 First verse +", + includeAllText: true, + includeMarkers: true + ); + + Assert.That(rows, Has.Length.EqualTo(8), string.Join(",", rows.Select(tr => tr.Text))); + Assert.That(rows[0].Text, Is.EqualTo("\\th1 Day")); + Assert.That(rows[0].Ref, Is.EqualTo(ScriptureRef.Parse("MAT 1:0/1:tr/1:th1"))); + Assert.That(rows[6].Text, Is.Empty); + Assert.That(rows[6].Ref, Is.EqualTo(ScriptureRef.Parse("MAT 1:0/3:p"))); + Assert.That(rows[7].Text, Is.EqualTo("First verse")); + Assert.That(rows[7].Ref, Is.EqualTo(ScriptureRef.Parse("MAT 1:1"))); + } + [Test] public void GetRows_VersePara_BeginningNonVerseSegment() {