mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Merge pull request #460 from mikeastock/do-not-mutate-cookie-hash
Use reject instead of delete_if to prevent mutation
This commit is contained in:
commit
1f8ed48fe4
2 changed files with 18 additions and 1 deletions
|
@ -16,6 +16,6 @@ class HTTParty::CookieHash < Hash #:nodoc:
|
|||
end
|
||||
|
||||
def to_cookie_string
|
||||
delete_if { |k, v| CLIENT_COOKIES.include?(k.to_s.downcase) }.collect { |k, v| "#{k}=#{v}" }.join("; ")
|
||||
reject { |k, v| CLIENT_COOKIES.include?(k.to_s.downcase) }.collect { |k, v| "#{k}=#{v}" }.join("; ")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -79,5 +79,22 @@ RSpec.describe HTTParty::CookieHash do
|
|||
@s = @cookie_hash.to_cookie_string
|
||||
expect(@s).not_to match(/Path=\//)
|
||||
end
|
||||
|
||||
it "should not mutate the hash" do
|
||||
original_hash = {
|
||||
"session" => "91e25e8b-6e32-418d-c72f-2d18adf041cd",
|
||||
"Max-Age" => "15552000",
|
||||
"cart" => "91e25e8b-6e32-418d-c72f-2d18adf041cd",
|
||||
"httponly" => nil,
|
||||
"Path" => "/",
|
||||
"secure" => nil,
|
||||
}
|
||||
|
||||
cookie_hash = HTTParty::CookieHash[original_hash]
|
||||
|
||||
cookie_hash.to_cookie_string
|
||||
|
||||
expect(cookie_hash).to eq(original_hash)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue