From 697865b86bcc2c4cc33c09dd516d02c1ba28e5a8 Mon Sep 17 00:00:00 2001 From: Steven Loria Date: Sat, 18 Mar 2017 12:44:19 -0400 Subject: [PATCH] Skip over lines that don't set an envvars This makes dotenv play better with .env files that do more than just set variables, e.g. defining aliases and functions closes #285 --- lib/dotenv/parser.rb | 2 -- spec/dotenv/parser_spec.rb | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/dotenv/parser.rb b/lib/dotenv/parser.rb index ae30c187..d6bdec56 100644 --- a/lib/dotenv/parser.rb +++ b/lib/dotenv/parser.rb @@ -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" end end diff --git a/spec/dotenv/parser_spec.rb b/spec/dotenv/parser_spec.rb index e28a237c..005ef0f8 100644 --- a/spec/dotenv/parser_spec.rb +++ b/spec/dotenv/parser_spec.rb @@ -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