Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #3685 (closed defect: fixed)

Opened 4 years ago

Last modified 3 years ago

[PATCH] ActionController::Cookies#delete does not delete cookies with a path other than '/'

Reported by: anonymous Assigned to: David
Priority: normal Milestone: 1.x
Component: ActionPack Version: edge
Severity: minor Keywords: verified tiny cookies
Cc:

Description

Using rails 1.0.0, actionpack 1.11.2; Relevant code is in action_controller/cookies.rb

Create a cookie with a path:

cookies[:foo] = { :value => 'xyz', :path => '/foo', :expires => Time.now.next_week }

Later, attempt to delete the cookie:

cookies.delete(:foo)

The cookie is not removed (at least with FireFox 1.5). You can remove it like this:

cookies[:foo] = { :value => , :path => '/foo', :expires => Time.at(0) }

It seems like the #delete method should take an options argument like []= does.

Attachments

delete_cookies_with_options.diff (1.7 kB) - added by Chris Wanstrath on 09/12/06 10:08:16.
delete_cookies_with_options.2.diff (1.7 kB) - added by josh on 03/10/07 22:16:37.
Updated patch against [6372].

Change History

09/12/06 10:07:51 changed by Chris Wanstrath

  • version changed from 1.0.0 to edge.
  • summary changed from ActionController::Cookies#delete does not delete cookies with a path other than '/' to [PATCH] ActionController::Cookies#delete does not delete cookies with a path other than '/'.

It'd be nice if Rails was able to figure out the path and other options automatically when you call #delete but it doesn't look like this information is currently loaded on a request. Anyway, if this functionally is desired here's the patch.

09/12/06 10:08:16 changed by Chris Wanstrath

  • attachment delete_cookies_with_options.diff added.

03/10/07 22:16:37 changed by josh

  • attachment delete_cookies_with_options.2.diff added.

Updated patch against [6372].

03/10/07 22:17:11 changed by josh

  • keywords set to verified tiny cookies.
  • milestone set to 1.x.

05/17/07 13:41:19 changed by loopdo

This bug still exists as of 1.2.3, and also applies to cookies with a domain set. The temporary fix is to manually reset the cookie akin to the above solution:

cookies[:foo] = { :value => nil, :domain => '.example.com', :expires => Time.at(0) }

07/01/07 23:28:02 changed by nzkoz

  • status changed from new to closed.
  • resolution set to fixed.

(In [7160]) Allow you to delete cookies with options. Closes #3685 [josh, Chris Wanstrath]