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
This commit is contained in:
Rick Olson 2007-10-20 17:30:01 +00:00
parent 17ac677a2d
commit c9fecf20ff
3 changed files with 15 additions and 2 deletions

View File

@ -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]

View File

@ -44,7 +44,10 @@ module ActionController #:nodoc:
# 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)

View File

@ -18,7 +18,7 @@ class CookieTest < Test::Unit::TestCase
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 @@ class CookieTest < Test::Unit::TestCase
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