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

Don't do substitutions if the variable is single quoted. #124

Merged
merged 1 commit into from
Jul 28, 2014
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
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