fixes #23060; editDistance wrongly compare the length of rune strings (#23062)

fixes #23060
This commit is contained in:
ringabout
2023-12-13 17:34:41 +08:00
committed by GitHub
parent e51e98997b
commit 7e1ea50bc3
2 changed files with 6 additions and 1 deletions

View File

@@ -18,7 +18,7 @@ proc editDistance*(a, b: string): int {.noSideEffect.} =
## This uses the `Levenshtein`:idx: distance algorithm with only a linear
## memory overhead.
runnableExamples: static: doAssert editdistance("Kitten", "Bitten") == 1
if len(a) > len(b):
if runeLen(a) > runeLen(b):
# make `b` the longer string
return editDistance(b, a)
# strip common prefix

5
tests/errmsgs/t23060.nim Normal file
View File

@@ -0,0 +1,5 @@
discard """
errormsg: "undeclared identifier: '♔♕♖♗♘♙'"
"""
♔♕♖♗♘♙ = 1