Skip to content

Commit 7a69a03

Browse files
committed
Fix return value of String.at/2 with negative position out of bounds
1 parent 16da928 commit 7a69a03

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/elixir/lib/string.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ defmodule String do
463463
real_pos = do_length(next_grapheme(string)) - abs(position)
464464
case real_pos >= 0 do
465465
true -> do_at(next_grapheme(string), real_pos, 0)
466-
false -> ""
466+
false -> nil
467467
end
468468
end
469469

lib/elixir/test/elixir/string_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ defmodule StringTest do
162162
assert String.at("л", 10) == nil
163163
assert String.at("elixir", -1) == "r"
164164
assert String.at("がガちゃ", -2) == "ち"
165-
assert String.at("л", -3) == ""
165+
assert String.at("л", -3) == nil
166166
assert String.at("Ā̀stute", 1) == "s"
167167
assert String.at("elixir",6) == nil
168168
end

0 commit comments

Comments
 (0)