Skip to content

Commit

Permalink
Don't do substitutions if the variable is single quoted.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericroberts committed Jul 11, 2014
1 parent 8f1bc8c commit d573bfe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/dotenv/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions spec/dotenv/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d573bfe

Please sign in to comment.