Skip to content

Commit

Permalink
merge [7978] from edge
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-stable@7979 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
technoweenie committed Oct 20, 2007
1 parent 257d860 commit 5285270
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Ensure that cookies handle array values correctly. Closes #9937 [queso]

*1.13.5* (October 12th, 2007)

* Backport: allow array and hash query parameters. Array route parameters are converted/to/a/path as before. #6765, #7047, #7462 [bgipsy, Jeremy McAnally, Dan Kubb, brendan, Diego Algorta Casamayou]
Expand Down
5 changes: 4 additions & 1 deletion actionpack/lib/action_controller/cookies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def initialize(controller)
# Returns the value of the cookie by +name+ -- or nil if no such cookie exists. You set new cookies using either the cookie method
# or 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)
Expand Down
10 changes: 9 additions & 1 deletion actionpack/test/controller/cookie_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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
Expand Down Expand Up @@ -91,6 +91,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
Expand Down

0 comments on commit 5285270

Please sign in to comment.