Skip to content

Commit

Permalink
Merge pull request #1309 from sillsdev/fixed-GetLongestUsefulCommonSu…
Browse files Browse the repository at this point in the history
…bstring

Fixed bug in GetLongestUsefulCommonSubstring when string ends with an ORC
  • Loading branch information
tombogle authored Jan 9, 2024
2 parents bf62a58 + 63e2490 commit be7e470
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Fixed

- [SIL.Core] Fixed bug in extension method GetLongestUsefulCommonSubstring when string ends with an Object replacement character

## [13.0.0] - 2023-12-07

### Added
15 changes: 15 additions & 0 deletions SIL.Core.Tests/Extensions/StringExtensionTests.cs
Original file line number Diff line number Diff line change
@@ -585,6 +585,21 @@ public void GetLongestUsefulCommonSubstring_PreventOrcMatching_WholeWordMatch()
Assert.IsTrue(fWholeWord);
}

/// ------------------------------------------------------------------------------------
/// <summary>
/// Test the GetLongestUsefulCommonSubstring method. This test ensures that we don't get
/// an index-out-of-range exception.
/// </summary>
/// ------------------------------------------------------------------------------------
[Test]
public void GetLongestUsefulCommonSubstring_StringEndsWithORC_NoIndexOutOfRangeError()
{
var s1 = "Cuándo pelearon el " + kObjReplacementChar + " y " + kObjReplacementChar;
var s2 = "Qué hicieron el " + kObjReplacementChar + " y " + kObjReplacementChar;
Assert.AreEqual("el", s1.GetLongestUsefulCommonSubstring(s2, out var fWholeWord));
Assert.IsTrue(fWholeWord);
}

/// ------------------------------------------------------------------------------------
/// <summary>
/// Test the GetLongestUsefulCommonSubstring method. This test tests that leading punctuation is
2 changes: 1 addition & 1 deletion SIL.Core/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -460,7 +460,7 @@ public static string GetLongestUsefulCommonSubstring(this string s1, string s2,
int ichOrc = s1.IndexOf(kszObject, ich, cchMatch, StringComparison.Ordinal);
if (ichOrc >= 0)
{
ich += ichOrc;
ich = ichOrc;
continue;
}

0 comments on commit be7e470

Please sign in to comment.