Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds specs and fix for \s after separator #399

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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