From d573bfe330a4a38e56c8f236888851a8f141c960 Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Fri, 11 Jul 2014 19:54:25 -0400 Subject: [PATCH] Don't do substitutions if the variable is single quoted. --- lib/dotenv/parser.rb | 6 ++++-- spec/dotenv/parser_spec.rb | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) 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