Skip to content

Commit

Permalink
Merge pull request #399 from l-schirrmeister/fix-spaces-after-seperator
Browse files Browse the repository at this point in the history
Adds specs and fix for \s after separator
  • Loading branch information
Andrew Nordman committed Jul 31, 2019
2 parents c9ddedd + 8def657 commit 93f2ca9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/dotenv/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ class Parser
[Dotenv::Substitutions::Variable, Dotenv::Substitutions::Command]

LINE = /
(?:^|\A) # beginning of line
\s* # leading whitespace
(?:export\s+)? # optional export
([\w\.]+) # key
(?:\s*=\s*?|:\s+?) # separator
( # optional value begin
'(?:\\'|[^'])*' # single quoted value
| # or
"(?:\\"|[^"])*" # double quoted value
| # or
[^\#\r\n]+ # unquoted value
)? # value end
\s* # trailing whitespace
(?:\#.*)? # optional comment
(?:$|\z) # end of line
(?:^|\A) # beginning of line
\s* # leading whitespace
(?:export\s+)? # optional export
([\w\.]+) # key
(?:\s*=\s*?|:\s+?) # separator
( # optional value begin
\s*'(?:\\'|[^'])*' # single quoted value
| # or
\s*"(?:\\"|[^"])*" # double quoted value
| # or
[^\#\r\n]+ # unquoted value
)? # value end
\s* # trailing whitespace
(?:\#.*)? # optional comment
(?:$|\z) # end of line
/x

class << self
Expand Down
8 changes: 8 additions & 0 deletions spec/dotenv/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def env(string)
expect(env("FOO=bar")).to eql("FOO" => "bar")
end

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

it "parses values with spaces around equal sign" do
expect(env("FOO =bar")).to eql("FOO" => "bar")
expect(env("FOO= bar")).to eql("FOO" => "bar")
Expand Down Expand Up @@ -143,6 +147,10 @@ def env(string)
expect(env('foo="bar#baz" # comment')).to eql("foo" => "bar#baz")
end

it "allows # in quoted value with spaces after seperator" do
expect(env('foo= "bar#baz" # comment')).to eql("foo" => "bar#baz")
end

it "ignores comment lines" do
expect(env("\n\n\n # HERE GOES FOO \nfoo=bar")).to eql("foo" => "bar")
end
Expand Down

0 comments on commit 93f2ca9

Please sign in to comment.