Skip to content

Commit

Permalink
Dont stream back cookie value if it was set to the same value
Browse files Browse the repository at this point in the history
  • Loading branch information
brainopia committed Aug 10, 2012
1 parent 058dc9a commit bbe634e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 6 additions & 4 deletions actionpack/lib/action_dispatch/middleware/cookies.rb
Expand Up @@ -170,12 +170,14 @@ def []=(key, options)
options = { :value => value }
end

@cookies[key.to_s] = value

handle_options(options)

@set_cookies[key.to_s] = options
@delete_cookies.delete(key.to_s)
if @cookies[key.to_s] != value or options[:expires]
@cookies[key.to_s] = value
@set_cookies[key.to_s] = options
@delete_cookies.delete(key.to_s)
end

value
end

Expand Down
14 changes: 13 additions & 1 deletion actionpack/test/dispatch/cookies_test.rb
Expand Up @@ -179,6 +179,18 @@ def test_setting_cookie
assert_equal({"user_name" => "david"}, @response.cookies)
end

def test_setting_the_same_value_to_cookie
request.cookies[:user_name] = 'david'
get :authenticate
assert response.cookies.empty?
end

def test_setting_the_same_value_to_permanent_cookie
request.cookies[:user_name] = 'Jamie'
get :set_permanent_cookie
assert response.cookies, 'user_name' => 'Jamie'
end

def test_setting_with_escapable_characters
get :set_with_with_escapable_characters
assert_cookie_header "that+%26+guy=foo+%26+bar+%3D%3E+baz; path=/"
Expand Down Expand Up @@ -564,4 +576,4 @@ def assert_not_cookie_header(expected)
assert_not_equal expected.split("\n"), header
end
end
end
end

0 comments on commit bbe634e

Please sign in to comment.