Skip to content

Commit

Permalink
Preserve repeated linebreaks when normalizing line endings
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Dec 18, 2024
1 parent 79c0f1c commit bf87415
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dotenv/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def call(...)

def initialize(string, overwrite: false)
# Convert line breaks to same format
@string = string.gsub(/[\n\r]+/, "\n")
@string = string.gsub(/\r\n?/, "\n")
@hash = {}
@overwrite = overwrite
end
Expand Down
5 changes: 5 additions & 0 deletions spec/dotenv/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ def env(...)
.to eql("foo" => "bar", "fizz" => "buzz")
end

it "does not ignore empty lines in quoted string" do
value = "a\n\nb\n\nc"
expect(env("FOO=\"#{value}\"")).to eql("FOO" => value)
end

it "ignores inline comments" do
expect(env("foo=bar # this is foo")).to eql("foo" => "bar")
end
Expand Down

0 comments on commit bf87415

Please sign in to comment.