Skip to content

Commit

Permalink
Do not remove blank strings on strip, closes elixir-lang#282
Browse files Browse the repository at this point in the history
THe previous behavior was wrong, the current behavior
matches Ruby and Perl.
  • Loading branch information
José Valim committed May 6, 2012
1 parent c7e4cfa commit da67254
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 1 addition & 6 deletions lib/regex.ex
Expand Up @@ -183,9 +183,7 @@ defmodule Regex do
"""
def split({ Regex, compiled, _, _ }, string, parts // :infinity) do
options = [{ :return, return_for(string) }, :trim, { :parts, parts }]
list = Erlang.re.split(string, compiled, options)
blank = blank_for(string)
lc l in list when l != blank, do: l
Erlang.re.split(string, compiled, options)
end

@doc %B"""
Expand Down Expand Up @@ -230,9 +228,6 @@ defmodule Regex do

# Private Helpers

defp blank_for(element) when is_binary(element), do: ""
defp blank_for(element) when is_list(element), do: ''

defp return_for(element) when is_binary(element), do: :binary
defp return_for(element) when is_list(element), do: :list

Expand Down
3 changes: 3 additions & 0 deletions test/elixir/regex_test.exs
Expand Up @@ -49,6 +49,9 @@ defmodule Regex.BinaryTest do
assert Regex.split(%r" ", "foo bar baz") == ["foo", "bar", "baz"]
assert Regex.split(%r" ", "foo bar baz", 2) == ["foo", "bar baz"]
assert Regex.split(%r"\s", "foobar") == ["foobar"]
assert Regex.split(%r" ", "foo bar baz") == ["foo", "bar", "baz"]
assert Regex.split(%r"=", "key=") == ["key", ""]
assert Regex.split(%r"=", "=value") == ["", "value"]
end

test :replace do
Expand Down

0 comments on commit da67254

Please sign in to comment.