Skip to content

Commit 31e24b3

Browse files
committed
Fix codepoint byte counting in slice, closes #11461
1 parent d3b38fb commit 31e24b3

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

lib/elixir/lib/string.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2736,7 +2736,7 @@ defmodule String do
27362736
end
27372737
end
27382738

2739-
defp codepoint_byte_size(cp) when cp <= 0x00FF, do: 1
2739+
defp codepoint_byte_size(cp) when cp <= 0x007F, do: 1
27402740
defp codepoint_byte_size(cp) when cp <= 0x07FF, do: 2
27412741
defp codepoint_byte_size(cp) when cp <= 0xFFFF, do: 3
27422742
defp codepoint_byte_size(_), do: 4

lib/elixir/test/elixir/string_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ defmodule StringTest do
652652
assert String.slice("あいうえお", -10..-15) == ""
653653
assert String.slice("hello あいうえお Unicode", 8..-1) == "うえお Unicode"
654654
assert String.slice("abc", -1..14) == "c"
655+
assert String.slice("a·̀ͯ‿.⁀:", 0..-2) == "a·̀ͯ‿.⁀"
655656

656657
assert_raise FunctionClauseError, fn ->
657658
String.slice(nil, 0..1)

0 commit comments

Comments
 (0)