diff --git a/lib/dotenv/parser.rb b/lib/dotenv/parser.rb index 8d298ad1..7ecebe29 100644 --- a/lib/dotenv/parser.rb +++ b/lib/dotenv/parser.rb @@ -48,8 +48,10 @@ def call value = value.gsub(/\\([^$])/, '\1') end - @@substitutions.each do |proc| - value = proc.call(value, hash) + if $1 != "'" + @@substitutions.each do |proc| + value = proc.call(value, hash) + end end hash[key] = value diff --git a/spec/dotenv/parser_spec.rb b/spec/dotenv/parser_spec.rb index f6a5874e..8e27c0b2 100644 --- a/spec/dotenv/parser_spec.rb +++ b/spec/dotenv/parser_spec.rb @@ -47,8 +47,12 @@ def env(string) expect(env('BAR=$FOO')).to eql('BAR' => '') end - it 'expands variables in quoted strings' do - expect(env("FOO=test\nBAR='quote $FOO'")).to eql('FOO' => 'test', 'BAR' => 'quote test') + it 'expands variables in double quoted strings' do + expect(env("FOO=test\nBAR=\"quote $FOO\"")).to eql('FOO' => 'test', 'BAR' => 'quote test') + end + + it 'does not expand variables in single quoted strings' do + expect(env("BAR='quote $FOO'")).to eql('BAR' => 'quote $FOO') end it 'does not expand escaped variables' do