diff --git a/lib/rack/test/cookie_jar.rb b/lib/rack/test/cookie_jar.rb index c6f617d..011f81b 100644 --- a/lib/rack/test/cookie_jar.rb +++ b/lib/rack/test/cookie_jar.rb @@ -12,7 +12,7 @@ class Cookie # :nodoc: # The name of the cookie, will be a string attr_reader :name - + # The value of the cookie, will be a string or nil if there is no value. attr_reader :value @@ -183,12 +183,10 @@ def delete(name) def merge(raw_cookies, uri = nil) return unless raw_cookies - if raw_cookies.is_a? String - raw_cookies = raw_cookies.split("\n") - raw_cookies.reject!(&:empty?) - end + raw_cookies = raw_cookies.split("\n") if raw_cookies.is_a? String raw_cookies.each do |raw_cookie| + next if raw_cookie.empty? cookie = Cookie.new(raw_cookie, uri, @default_host) self << cookie if cookie.valid?(uri) end diff --git a/spec/rack/test/cookie_jar_spec.rb b/spec/rack/test/cookie_jar_spec.rb index 68a9587..854c582 100644 --- a/spec/rack/test/cookie_jar_spec.rb +++ b/spec/rack/test/cookie_jar_spec.rb @@ -67,4 +67,17 @@ jar.merge('c=d; domain=example.org; secure', URI.parse('/')) jar.to_hash.must_equal 'a' => 'b' end + + it '#merge ignores empty cookies in cookie strings' do + jar = Rack::Test::CookieJar.new + jar.merge('', URI.parse('/')) + jar.merge("\nc=d") + jar.to_hash.must_equal 'c' => 'd' + end + + it '#merge ignores empty cookies in cookie arrays' do + jar = Rack::Test::CookieJar.new + jar.merge(['', 'c=d'], URI.parse('/')) + jar.to_hash.must_equal 'c' => 'd' + end end