Skip to content

Commit

Permalink
Space is not required for Set-Cookie header
Browse files Browse the repository at this point in the history
  • Loading branch information
ykzts committed Jul 5, 2013
1 parent 37aaaa7 commit ce89251
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions actionpack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Ignore spaces around delimiter in Set-Cookie header.

*Yamagishi Kazutoshi*

* Remove deprecated Rails application fallback for integration testing, set
`ActionDispatch.test_app` instead.

Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/middleware/ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def flag_cookies_as_secure!(headers)
cookies = cookies.split("\n")

headers['Set-Cookie'] = cookies.map { |cookie|
if cookie !~ /;\s+secure(;|$)/i
if cookie !~ /;\s*secure\s*(;|$)/i
"#{cookie}; secure"
else
cookie
Expand Down
29 changes: 29 additions & 0 deletions actionpack/test/dispatch/ssl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,35 @@ def test_flag_cookies_as_secure_with_more_spaces_after
response.headers['Set-Cookie'].split("\n")
end


def test_flag_cookies_as_secure_with_has_not_spaces_before
self.app = ActionDispatch::SSL.new(lambda { |env|
headers = {
'Content-Type' => "text/html",
'Set-Cookie' => "problem=def; path=/;secure; HttpOnly"
}
[200, headers, ["OK"]]
})

get "https://example.org/"
assert_equal ["problem=def; path=/;secure; HttpOnly"],
response.headers['Set-Cookie'].split("\n")
end

def test_flag_cookies_as_secure_with_has_not_spaces_after
self.app = ActionDispatch::SSL.new(lambda { |env|
headers = {
'Content-Type' => "text/html",
'Set-Cookie' => "problem=def; path=/; secure;HttpOnly"
}
[200, headers, ["OK"]]
})

get "https://example.org/"
assert_equal ["problem=def; path=/; secure;HttpOnly"],
response.headers['Set-Cookie'].split("\n")
end

def test_flag_cookies_as_secure_with_ignore_case
self.app = ActionDispatch::SSL.new(lambda { |env|
headers = {
Expand Down

0 comments on commit ce89251

Please sign in to comment.