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

Skip over lines that don't set an envvars #291

Merged
merged 1 commit into from
Apr 13, 2018
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
2 changes: 0 additions & 2 deletions lib/dotenv/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ def parse_line(line)
if variable_not_set?(line)
raise FormatError, "Line #{line.inspect} has an unset variable"
end
elsif line !~ /\A\s*(?:#.*)?\z/ # not comment or blank line
raise FormatError, "Line #{line.inspect} doesn't match format"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to warn on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong feeling about it, but I would think not. We don't expect every line to follow this format, so we shouldn't raise a warning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just warn once when the file parsing is finished 😁?

end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/dotenv/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def env(string)
expect(env("foo=bar ")).to eql("foo" => "bar") # not 'bar '
end

it "throws an error if line format is incorrect" do
expect { env("lol$wut") }.to raise_error(Dotenv::FormatError)
it "ignores lines that are not variable assignments" do
expect(env("lol$wut")).to eql({})
end

it "ignores empty lines" do
Expand Down