Skip to content

Commit

Permalink
Merge pull request #277 from h-takisawa/following_space
Browse files Browse the repository at this point in the history
Allow following whitespace
  • Loading branch information
bkeepers authored Jan 19, 2017
2 parents be155c2 + 84f33f4 commit 63854ce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/dotenv/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class Parser
| # or
[^#\n]+ # unquoted value
)? # value end
(?:\s*\#.*)? # optional comment
\s*
(?:\#.*)? # optional comment
\z
/x

Expand Down
17 changes: 17 additions & 0 deletions spec/dotenv/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,26 @@ def env(string)
expect(env(" FOO=bar")).to eql("FOO" => "bar")
end

it "parses values with following spaces" do
expect(env("FOO=bar ")).to eql("FOO" => "bar")
end

it "parses double quoted values" do
expect(env('FOO="bar"')).to eql("FOO" => "bar")
end

it "parses double quoted values with following spaces" do
expect(env('FOO="bar" ')).to eql("FOO" => "bar")
end

it "parses single quoted values" do
expect(env("FOO='bar'")).to eql("FOO" => "bar")
end

it "parses single quoted values with following spaces" do
expect(env("FOO='bar' ")).to eql("FOO" => "bar")
end

it "parses escaped double quotes" do
expect(env('FOO="escaped\"bar"')).to eql("FOO" => 'escaped"bar')
end
Expand Down Expand Up @@ -128,6 +140,11 @@ def env(string)
expect(env("foo='ba#r'")).to eql("foo" => "ba#r")
end

it "parses # in quoted values with following spaces" do
expect(env('foo="ba#r" ')).to eql("foo" => "ba#r")
expect(env("foo='ba#r' ")).to eql("foo" => "ba#r")
end

if RUBY_VERSION > "1.8.7"
it "parses shell commands interpolated in $()" do
expect(env("echo=$(echo hello)")).to eql("echo" => "hello")
Expand Down

0 comments on commit 63854ce

Please sign in to comment.