diff --git a/history.md b/history.md index 4a46081..b539368 100644 --- a/history.md +++ b/history.md @@ -6,6 +6,7 @@ - added parameter passing for get request using the :param key in header - the warning about the logger when using a string was a bad idea - multipart parameters names should not be escaped +- remove the cookie escaping introduced by migrating to CGI cookie parsing in 1.5.1 # 1.5.1 diff --git a/lib/restclient/abstract_response.rb b/lib/restclient/abstract_response.rb index 0c65ee7..813a06b 100644 --- a/lib/restclient/abstract_response.rb +++ b/lib/restclient/abstract_response.rb @@ -27,7 +27,7 @@ module RestClient @cookies ||= (self.headers[:set_cookie] || {}).inject({}) do |out, cookie_content| CGI::Cookie::parse(cookie_content).each do |key, cookie| unless ['expires', 'path'].include? key - out[key] = cookie.value[0] || '' + out[CGI::escape(key)] = cookie.value[0] ? (CGI::escape(cookie.value[0]) || '') : '' end end out diff --git a/lib/restclient/request.rb b/lib/restclient/request.rb index 609366d..eb7135e 100644 --- a/lib/restclient/request.rb +++ b/lib/restclient/request.rb @@ -85,7 +85,7 @@ module RestClient def make_headers user_headers unless @cookies.empty? - user_headers[:cookie] = @cookies.map { |(key, val)| "#{key.to_s}=#{val}" }.sort.join(';') + user_headers[:cookie] = @cookies.map { |(key, val)| "#{key.to_s}=#{CGI::unescape(val)}" }.sort.join(';') end headers = stringify_headers(default_headers).merge(stringify_headers(user_headers)) headers.merge!(@payload.headers) if @payload diff --git a/spec/abstract_response_spec.rb b/spec/abstract_response_spec.rb index 6e95581..56f3a97 100644 --- a/spec/abstract_response_spec.rb +++ b/spec/abstract_response_spec.rb @@ -53,7 +53,12 @@ describe RestClient::AbstractResponse do it "extract strange cookies" do @net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=ZJ/HQVH6YE+rVkTpn0zvTQ==; path=/']) - @response.cookies.should == { 'session_id' => 'ZJ/HQVH6YE rVkTpn0zvTQ==' } + @response.cookies.should == { 'session_id' => 'ZJ%2FHQVH6YE+rVkTpn0zvTQ%3D%3D' } + end + + it "doesn't escape cookies" do + @net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=BAh7BzoNYXBwX25hbWUiEGFwcGxpY2F0aW9uOgpsb2dpbiIKYWRtaW4%3D%0A--08114ba654f17c04d20dcc5228ec672508f738ca; path=/']) + @response.cookies.should == { 'session_id' => 'BAh7BzoNYXBwX25hbWUiEGFwcGxpY2F0aW9uOgpsb2dpbiIKYWRtaW4%3D%0A--08114ba654f17c04d20dcc5228ec672508f738ca' } end it "can access the net http result directly" do