From 7e1ea50bc3a495bc8feb69ceb9856a0a28ecc2e9 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 13 Dec 2023 17:34:41 +0800 Subject: [PATCH] fixes #23060; `editDistance` wrongly compare the length of rune strings (#23062) fixes #23060 --- lib/std/editdistance.nim | 2 +- tests/errmsgs/t23060.nim | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 tests/errmsgs/t23060.nim diff --git a/lib/std/editdistance.nim b/lib/std/editdistance.nim index 6a25ca4b94..40c0017ae0 100644 --- a/lib/std/editdistance.nim +++ b/lib/std/editdistance.nim @@ -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 diff --git a/tests/errmsgs/t23060.nim b/tests/errmsgs/t23060.nim new file mode 100644 index 0000000000..abb79bcc32 --- /dev/null +++ b/tests/errmsgs/t23060.nim @@ -0,0 +1,5 @@ +discard """ + errormsg: "undeclared identifier: '♔♕♖♗♘♙'" +""" + +♔♕♖♗♘♙ = 1 \ No newline at end of file