Skip to content

Commit bf87415

Browse files
committed
Preserve repeated linebreaks when normalizing line endings
1 parent 79c0f1c commit bf87415

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/dotenv/parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def call(...)
4343

4444
def initialize(string, overwrite: false)
4545
# Convert line breaks to same format
46-
@string = string.gsub(/[\n\r]+/, "\n")
46+
@string = string.gsub(/\r\n?/, "\n")
4747
@hash = {}
4848
@overwrite = overwrite
4949
end

spec/dotenv/parser_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ def env(...)
158158
.to eql("foo" => "bar", "fizz" => "buzz")
159159
end
160160

161+
it "does not ignore empty lines in quoted string" do
162+
value = "a\n\nb\n\nc"
163+
expect(env("FOO=\"#{value}\"")).to eql("FOO" => value)
164+
end
165+
161166
it "ignores inline comments" do
162167
expect(env("foo=bar # this is foo")).to eql("foo" => "bar")
163168
end

0 commit comments

Comments
 (0)