Skip to content

Commit

Permalink
Fix for TestResponse.cookies returning cookies unescaped [#1867 state…
Browse files Browse the repository at this point in the history
…:resolved]

Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
  • Loading branch information
dmcinnes authored and dhh committed Apr 7, 2009
1 parent ace154d commit dc69d93
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions actionpack/CHANGELOG
@@ -1,3 +1,8 @@
*Edge*

* Fixed that TestResponse.cookies was returning cookies unescaped #1867 [Doug McInnes]


*2.3.2 [Final] (March 15, 2009)*

* Fixed that redirection would just log the options, not the final url (which lead to "Redirected to #<Post:0x23150b8>") [DHH]
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/test_process.rb
Expand Up @@ -258,7 +258,7 @@ def has_template_object?(name=nil)
def cookies
cookies = {}
Array(headers['Set-Cookie']).each do |cookie|
key, value = cookie.split(";").first.split("=")
key, value = cookie.split(";").first.split("=").map {|val| Rack::Utils.unescape(val)}
cookies[key] = value
end
cookies
Expand Down
10 changes: 10 additions & 0 deletions actionpack/test/controller/cookie_test.rb
Expand Up @@ -6,6 +6,10 @@ def authenticate
cookies["user_name"] = "david"
end

def set_with_with_escapable_characters
cookies["that & guy"] = "foo & bar => baz"
end

def authenticate_for_fourteen_days
cookies["user_name"] = { "value" => "david", "expires" => Time.utc(2005, 10, 10,5) }
end
Expand Down Expand Up @@ -53,6 +57,12 @@ def test_setting_cookie
assert_equal({"user_name" => "david"}, @response.cookies)
end

def test_setting_with_escapable_characters
get :set_with_with_escapable_characters
assert_equal ["that+%26+guy=foo+%26+bar+%3D%3E+baz; path=/"], @response.headers["Set-Cookie"]
assert_equal({"that & guy" => "foo & bar => baz"}, @response.cookies)
end

def test_setting_cookie_for_fourteen_days
get :authenticate_for_fourteen_days
assert_equal ["user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT"], @response.headers["Set-Cookie"]
Expand Down

0 comments on commit dc69d93

Please sign in to comment.