Permalink
Browse files

Ensure that cookies handle array values correctly. Closes #9937 [queso]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7978 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 17ac677 commit c9fecf20ffb051ebc9270bfd787fd2964349d19a @technoweenie technoweenie committed Oct 20, 2007
Showing with 15 additions and 2 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +4 −1 actionpack/lib/action_controller/cookies.rb
  3. +9 −1 actionpack/test/controller/cookie_test.rb
@@ -1,5 +1,7 @@
*SVN*
+* Ensure that cookies handle array values correctly. Closes #9937 [queso]
+
* Make sure resource routes don't clash with internal helpers like javascript_path, image_path etc. #9928 [gbuesing]
* caches_page uses a single after_filter instead of one per action. #9891 [lifofifo]
@@ -44,7 +44,10 @@ def initialize(controller)
# Returns the value of the cookie by +name+ -- or nil if no such cookie exists. You set new cookies using cookies[]=
# (for simple name/value cookies without options).
def [](name)
- @cookies[name.to_s].value.first if @cookies[name.to_s] && @cookies[name.to_s].respond_to?(:value)
+ cookie = @cookies[name.to_s]
+ if cookie && cookie.respond_to?(:value)
+ cookie.size > 1 ? cookie.value : cookie.value.to_s
+ end
end
def []=(name, options)
@@ -18,7 +18,7 @@ def set_multiple_cookies
cookies["user_name"] = { "value" => "david", "expires" => Time.local(2005, 10, 10) }
cookies["login"] = "XJ-122"
end
-
+
def access_frozen_cookies
cookies["will"] = "work"
end
@@ -92,6 +92,14 @@ def test_cookiejar_accessor
assert_equal nil, jar["something_else"]
end
+ def test_cookiejar_accessor_with_array_value
+ a = %w{1 2 3}
+ @request.cookies["pages"] = CGI::Cookie.new("name" => "pages", "value" => a, "expires" => Time.local(2025, 10, 10))
+ @controller.request = @request
+ jar = ActionController::CookieJar.new(@controller)
+ assert_equal a, jar["pages"]
+ end
+
def test_delete_cookie_with_path
get :delete_cookie_with_path
assert_equal "/beaten", @response.headers["cookie"].first.path

0 comments on commit c9fecf2

Please sign in to comment.