Skip to content

Commit

Permalink
Merge pull request bkeepers#194 from flyfy1/master
Browse files Browse the repository at this point in the history
supporting carriage return
  • Loading branch information
bkeepers committed Jun 19, 2015
2 parents 05e628c + 693023f commit 748b1db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/dotenv/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def initialize(string)
end

def call
@string.split("\n").each do |line|
@string.split(/[\n\r]+/).each do |line|
parse_line(line)
end
@hash
Expand Down Expand Up @@ -83,7 +83,7 @@ def unescape_characters(value)
end

def expand_newlines(value)
value.gsub('\n', "\n")
value.gsub('\n', "\n").gsub('\r', "\r")
end

def variable_not_set?(line)
Expand Down
12 changes: 12 additions & 0 deletions spec/dotenv/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ def env(string)
.to eql("Quotes won't be a problem")
end

it "supports carriage return" do
expect(env("FOO=bar\rbaz=fbb")).to eql("FOO" => "bar", "baz" => "fbb")
end

it "supports carriage return combine with new line" do
expect(env("FOO=bar\r\nbaz=fbb")).to eql("FOO" => "bar", "baz" => "fbb")
end

it "expands carriage return in quoted strings" do
expect(env('FOO="bar\rbaz"')).to eql("FOO" => "bar\rbaz")
end

# This functionality is not supported on JRuby or Rubinius
if (!defined?(RUBY_ENGINE) || RUBY_ENGINE != "jruby") &&
!defined?(Rubinius)
Expand Down

0 comments on commit 748b1db

Please sign in to comment.