Skip to content

Commit d3f7204

Browse files
committed
Fix crash when denormalizing quotation marks in an invalid chapter
1 parent 4db48d7 commit d3f7204

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/SIL.Machine/PunctuationAnalysis/QuotationMarkUpdateSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public QuotationMarkUpdateSettings(
1818

1919
public QuotationMarkUpdateStrategy GetActionForChapter(int chapterNumber)
2020
{
21-
if (chapterNumber <= _chapterActions.Count)
21+
if (chapterNumber > -1 && chapterNumber <= _chapterActions.Count)
2222
{
2323
return _chapterActions[chapterNumber - 1];
2424
}

tests/SIL.Machine.Tests/PunctuationAnalysis/QuoteConventionChangingUsfmBlockUpdateHandlerTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,31 @@ public void StartNewChapter()
830830
);
831831
}
832832

833+
[Test]
834+
public void InvalidChapterNumber()
835+
{
836+
string inputUsfm =
837+
@"\c 1
838+
\p
839+
\v 1 Chapter 1, ""Verse 1""
840+
\c 2.
841+
\p
842+
\v v1 Chapter 2, ""Invalid Verse 1""
843+
";
844+
845+
string expectedUsfm = (
846+
"\\c 1\n"
847+
+ "\\p\n"
848+
+ "\\v 1 Chapter 1, “Verse 1”\n"
849+
+ "\\c 2.\n"
850+
+ "\\p\n"
851+
+ "\\v v1 Chapter 2, “Invalid Verse 1”"
852+
);
853+
854+
string observedUsfm = ChangeQuotationMarks(inputUsfm, "typewriter_english", "standard_english");
855+
AssertUsfmEqual(observedUsfm, expectedUsfm);
856+
}
857+
833858
private static string ChangeQuotationMarks(
834859
string normalizedUsfm,
835860
string sourceQuoteConventionName,

0 commit comments

Comments
 (0)