diff --git a/lib/dotenv/environment.rb b/lib/dotenv/environment.rb
index <HASH>..<HASH> 100644
--- a/lib/dotenv/environment.rb
+++ b/lib/dotenv/environment.rb
@@ -11,7 +11,7 @@ module Dotenv
       read.each do |line|
         if match = line.match(LINE)
           key, value = match.to_a.drop(1)
-          value = value.sub(/\A(['"])(.*)\1\z/, '\2')
+          value = value.strip.sub(/\A(['"])(.*)\1\z/, '\2')
           value = value.gsub('\n', "\n").gsub(/\\(.)/, '\1') if $1 == '"'
           self[key] = value
         end
diff --git a/spec/dotenv/environment_spec.rb b/spec/dotenv/environment_spec.rb
index <HASH>..<HASH> 100644
--- a/spec/dotenv/environment_spec.rb
+++ b/spec/dotenv/environment_spec.rb
@@ -66,6 +66,10 @@ describe Dotenv::Environment do
     expect(env('FOO.BAR=foobar')).to eql('FOO.BAR' => 'foobar')
   end
 
+  it 'strips unquoted values' do
+    expect(env('foo=bar ')).to eql('foo' => 'bar') # not 'bar '
+  end
+
   require 'tempfile'
   def env(text)
     file = Tempfile.new('dotenv')
Allow parser to strip unquoted values