diff --git a/src/SIL.Machine/PunctuationAnalysis/QuotationMarkUpdateSettings.cs b/src/SIL.Machine/PunctuationAnalysis/QuotationMarkUpdateSettings.cs index 3b124e83..be6bbc31 100644 --- a/src/SIL.Machine/PunctuationAnalysis/QuotationMarkUpdateSettings.cs +++ b/src/SIL.Machine/PunctuationAnalysis/QuotationMarkUpdateSettings.cs @@ -18,7 +18,7 @@ public QuotationMarkUpdateSettings( public QuotationMarkUpdateStrategy GetActionForChapter(int chapterNumber) { - if (chapterNumber <= _chapterActions.Count) + if (chapterNumber > -1 && chapterNumber <= _chapterActions.Count) { return _chapterActions[chapterNumber - 1]; } diff --git a/tests/SIL.Machine.Tests/PunctuationAnalysis/QuoteConventionChangingUsfmBlockUpdateHandlerTests.cs b/tests/SIL.Machine.Tests/PunctuationAnalysis/QuoteConventionChangingUsfmBlockUpdateHandlerTests.cs index dd9ca727..f021bddf 100644 --- a/tests/SIL.Machine.Tests/PunctuationAnalysis/QuoteConventionChangingUsfmBlockUpdateHandlerTests.cs +++ b/tests/SIL.Machine.Tests/PunctuationAnalysis/QuoteConventionChangingUsfmBlockUpdateHandlerTests.cs @@ -830,6 +830,31 @@ public void StartNewChapter() ); } + [Test] + public void InvalidChapterNumber() + { + string inputUsfm = + @"\c 1 + \p + \v 1 Chapter 1, ""Verse 1"" + \c 2. + \p + \v v1 Chapter 2, ""Invalid Verse 1"" + "; + + string expectedUsfm = ( + "\\c 1\n" + + "\\p\n" + + "\\v 1 Chapter 1, “Verse 1”\n" + + "\\c 2.\n" + + "\\p\n" + + "\\v v1 Chapter 2, “Invalid Verse 1”" + ); + + string observedUsfm = ChangeQuotationMarks(inputUsfm, "typewriter_english", "standard_english"); + AssertUsfmEqual(observedUsfm, expectedUsfm); + } + private static string ChangeQuotationMarks( string normalizedUsfm, string sourceQuoteConventionName,