Skip to content

Commit 41b5091

Browse files
gringoclJosé Valim
authored andcommitted
Fix nfd normalization bug (#4606)
* Fix nfd normalization bug * Change String.normalize return type to binary Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
1 parent e5374cf commit 41b5091

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

lib/elixir/lib/string.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,14 +504,14 @@ defmodule String do
504504
## Examples
505505
506506
iex> String.normalize("yêṩ", :nfd)
507-
"yêṩ"
507+
"yêṩ"
508508
509509
iex> String.normalize("leña", :nfc)
510510
"leña"
511511
512512
"""
513-
@spec normalize(t, atom) :: boolean
514-
defdelegate normalize(binary, form), to: String.Normalizer
513+
@spec normalize(t, atom) :: t
514+
defdelegate normalize(string, form), to: String.Normalizer
515515

516516
@doc """
517517
Converts all characters in the given string to uppercase.

lib/elixir/test/elixir/string_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ defmodule StringTest do
333333

334334
test "normalize" do
335335
assert String.normalize("ŝ", :nfd) == "ŝ"
336-
assert String.normalize("ḇravô", :nfd) == "ḇravô"
336+
assert String.normalize("ḇravô", :nfd) == "ḇravô"
337337
assert String.normalize("ṩierra", :nfd) == "ṩierra"
338338
assert String.normalize("뢴", :nfd) == "뢴"
339339
assert String.normalize("êchǭ", :nfc) == "êchǭ"

lib/elixir/unicode/unicode.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ defmodule String.Normalizer do
505505
{n, rest} = String.Unicode.next_grapheme_size(binary)
506506
part = :binary.part(binary, 0, n)
507507
case n do
508-
1 -> normalize_nfc(rest, acc <> part)
508+
1 -> normalize_nfd(rest, acc <> part)
509509
_ -> normalize_nfd(rest, acc <> canonical_order(part, []))
510510
end
511511
end

0 commit comments

Comments
 (0)