lib/patron/request.rb in patron-0.4.10 vs lib/patron/request.rb in patron-0.4.11
- old
+ new
@@ -21,10 +21,12 @@
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
## THE SOFTWARE.
##
## -------------------------------------------------------------------
+require 'cgi'
+
module Patron
# Represents the information necessary for an HTTP request.
# This is basically a data object with validation. Not all fields will be
# used in every request.
@@ -142,9 +144,10 @@
def hash_to_string(hash)
pairs = []
recursive = Proc.new do |h, prefix|
h.each_pair do |k,v|
key = prefix == '' ? k : "#{prefix}[#{k}]"
+ @action == :post ? v = CGI::escape(v.to_s) : v
v.is_a?(Hash) ? recursive.call(v, key) : pairs << "#{key}=#{v}"
end
end
recursive.call(hash, '')
return pairs.join('&')