elixir
elixir copied to clipboard
String.strip/2 breaks for empty strings
iex(1)> String.strip("")
** (ArgumentError) argument error
:binary.last("")
/home/alexrp/Projects/elixir/lib/elixir/lib/string.ex:194: String.rstrip/2
erl_eval.erl:572: :erl_eval.do_apply/6
src/elixir.erl:113: :elixir.eval_forms/3
/home/alexrp/Projects/elixir/lib/iex/lib/iex/loop.ex:18: IEx.Loop.do_loop/1
The reason seems to be that the rstrip code unconditionally calls :binary.last/1 which will fail if the binary is empty.
I also believe that it makes sense to ensure that the split doesn't break if you type an empty string as the second parameter String.split("elixir", "")
iex(3)> String.split("elixir","")
** (ArgumentError) argument error
binary.erl:84: :binary.split/3
erl_eval.erl:572: :erl_eval.do_apply/6
src/elixir.erl:113: :elixir.eval_forms/3
/desenv/elixir/lib/iex/lib/iex/loop.ex:18: IEx.Loop.do_loop/1
I suggest to adopt the same solution of split that ruby has
"elixir".split("")
=> ["e", "l", "i", "x", "i", "r"]
edit: I'm sorry guys, I read it wrong... this issue is applied for strip, the error I found is for split. should another issue be open?