diff --git a/lib/restclient/payload.rb b/lib/restclient/payload.rb index 518bdd4..a036139 100644 --- a/lib/restclient/payload.rb +++ b/lib/restclient/payload.rb @@ -147,12 +147,17 @@ module RestClient # for UrlEncoded escape the keys def handle_key key - URI.escape(key.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) + parser.escape(key.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) end def headers super.merge({'Content-Type' => 'application/x-www-form-urlencoded'}) end + + private + def parser + URI.const_defined?(:Parser) ? URI::Parser.new : URI + end end class Multipart < Base diff --git a/lib/restclient/request.rb b/lib/restclient/request.rb index 56802b3..fe05fbc 100644 --- a/lib/restclient/request.rb +++ b/lib/restclient/request.rb @@ -137,7 +137,7 @@ module RestClient if p[k].is_a? Hash process_payload(p[k], key) else - value = URI.escape(p[k].to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) + value = parser.escape(p[k].to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) "#{key}=#{value}" end end.join("&") @@ -312,6 +312,11 @@ module RestClient {:accept => '*/*; q=0.5, application/xml', :accept_encoding => 'gzip, deflate'} end + private + def parser + URI.const_defined?(:Parser) ? URI::Parser.new : URI + end + end end