Skip to content

Commit ad778a6

Browse files
committed
Fix capitalize for single codepoint (#13268)
1 parent c35edd1 commit ad778a6

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

lib/elixir/lib/string.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@ defmodule String do
966966

967967
def capitalize(string, mode) when is_binary(string) do
968968
case :unicode_util.gc(string) do
969+
[gc] -> grapheme_to_binary(:string.titlecase([gc]))
969970
[gc, rest] -> grapheme_to_binary(:string.titlecase([gc])) <> downcase(rest, mode)
970971
[gc | rest] -> grapheme_to_binary(:string.titlecase([gc])) <> downcase(rest, mode)
971972
[] -> ""

lib/elixir/test/elixir/string_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ defmodule StringTest do
254254

255255
test "capitalize/1" do
256256
assert String.capitalize("") == ""
257+
assert String.capitalize("1") == "1"
257258
assert String.capitalize("abc") == "Abc"
258259
assert String.capitalize("ABC") == "Abc"
259260
assert String.capitalize("c b a") == "C b a"

0 commit comments

Comments
 (0)