Permalink
Browse files

Fix cookie deletion with path specified

  • Loading branch information...
1 parent 6573154 commit eead3b2206758699641740eeb0d4d8fa3c690088 Joe Van Dyk committed Jul 13, 2011
Showing with 14 additions and 0 deletions.
  1. +2 −0 lib/rack/utils.rb
  2. +12 −0 test/spec_response.rb
View
@@ -228,6 +228,8 @@ def delete_cookie_header!(header, key, value = {})
cookies.reject! { |cookie|
if value[:domain]
cookie =~ /\A#{escape(key)}=.*domain=#{value[:domain]}/
+ elsif value[:path]
+ cookie =~ /\A#{escape(key)}=.*path=#{value[:path]}/
else
cookie =~ /\A#{escape(key)}=/
end
View
@@ -109,6 +109,18 @@
"foo=; domain=sample.example.com; expires=Thu, 01-Jan-1970 00:00:00 GMT"].join("\n")
end
+ it "can delete cookies with the same name with different paths" do
+ response = Rack::Response.new
+ response.set_cookie "foo", {:value => "bar", :path => "/"}
+ response.set_cookie "foo", {:value => "bar", :path => "/path"}
+ response["Set-Cookie"].should.equal ["foo=bar; path=/",
+ "foo=bar; path=/path"].join("\n")
+
+ response.delete_cookie "foo", :path => "/path"
+ response["Set-Cookie"].should.equal ["foo=bar; path=/",
+ "foo=; path=/path; expires=Thu, 01-Jan-1970 00:00:00 GMT"].join("\n")
+ end
+
it "can do redirects" do
response = Rack::Response.new
response.redirect "/foo"

0 comments on commit eead3b2

Please sign in to comment.