Permalink
Browse files

Fix return value of String.at/2 with negative position out of bounds

  • Loading branch information...
1 parent 16da928 commit 7a69a0335c363e9196f80ab9c57539df7626c1ec @yrashk yrashk committed Dec 4, 2012
Showing with 2 additions and 2 deletions.
  1. +1 −1 lib/elixir/lib/string.ex
  2. +1 −1 lib/elixir/test/elixir/string_test.exs
View
@@ -463,7 +463,7 @@ defmodule String do
real_pos = do_length(next_grapheme(string)) - abs(position)
case real_pos >= 0 do
true -> do_at(next_grapheme(string), real_pos, 0)
- false -> ""
+ false -> nil
end
end
@@ -162,7 +162,7 @@ defmodule StringTest do
assert String.at("л", 10) == nil
assert String.at("elixir", -1) == "r"
assert String.at("がガちゃ", -2) == ""
- assert String.at("л", -3) == ""
+ assert String.at("л", -3) == nil
assert String.at("Ā̀stute", 1) == "s"
assert String.at("elixir",6) == nil
end

0 comments on commit 7a69a03

Please sign in to comment.