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:
parent
17ac677a2d
commit
c9fecf20ff
|
@ -1,5 +1,7 @@
|
||||||
*SVN*
|
*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]
|
* 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]
|
* caches_page uses a single after_filter instead of one per action. #9891 [lifofifo]
|
||||||
|
|
|
@ -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[]=
|
# 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).
|
# (for simple name/value cookies without options).
|
||||||
def [](name)
|
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
|
end
|
||||||
|
|
||||||
def []=(name, options)
|
def []=(name, options)
|
||||||
|
|
|
@ -92,6 +92,14 @@ class CookieTest < Test::Unit::TestCase
|
||||||
assert_equal nil, jar["something_else"]
|
assert_equal nil, jar["something_else"]
|
||||||
end
|
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
|
def test_delete_cookie_with_path
|
||||||
get :delete_cookie_with_path
|
get :delete_cookie_with_path
|
||||||
assert_equal "/beaten", @response.headers["cookie"].first.path
|
assert_equal "/beaten", @response.headers["cookie"].first.path
|
||||||
|
|
Loading…
Reference in New Issue