Skip to content

Commit eafe765

Browse files
committed
patch #194
1 parent bd2ecb3 commit eafe765

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/CatLib.Core.Tests/Support/Util/StrTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,12 @@ public void TestLevenshteinLargeThan255()
368368
Assert.AreEqual(-1, Str.Levenshtein(builder.ToString(), "world"));
369369
}
370370

371+
[TestMethod]
372+
public void TestLevenshteinNull()
373+
{
374+
Assert.AreEqual(-1, Str.Levenshtein(null, "1"));
375+
}
376+
371377
[TestMethod]
372378
public void TestJoinList()
373379
{

src/CatLib.Core/Support/Util/Str.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,11 @@ public static string Truncate(string str, int length, object separator = null, s
503503
/// </returns>
504504
public static int Levenshtein(string str1, string str2)
505505
{
506+
if (str1 == null || str2 == null)
507+
{
508+
return -1;
509+
}
510+
506511
var length1 = str1.Length;
507512
var length2 = str2.Length;
508513

0 commit comments

Comments
 (0)