Skip to content
Browse files

support escape mehtod for original mruby

  • Loading branch information...
1 parent c2e4a71 commit 499ccf6c30cf80906f1413b2735d6486c3c2359c @matsumoto-r committed Dec 31, 2012
Showing with 22 additions and 1 deletion.
  1. +22 −1 mrblib/httprequest.rb
View
23 mrblib/httprequest.rb
@@ -36,7 +36,7 @@ def request(method, url, body, headers)
def encode_parameters(params, delimiter = '&', quote = nil)
if params.is_a?(Hash)
params = params.map do |key, value|
- sprintf("%s=%s%s%s", key, quote, value, quote)
+ sprintf("%s=%s%s%s", escape(key), quote, escape(value), quote)
end
else
params = params.map { |value| escape(value) }
@@ -57,4 +57,25 @@ def create_http_request(method, body, headers)
end
request
end
+ #def escape(str, unsafe = nil)
+ def escape(str)
+ reserved_str = [
+ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "n", "m", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
+ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
+ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
+ "-", ".", "_", "~"
+ ]
+ tmp = ''
+ str = str.to_s
+ str.size.times do |idx|
+ chr = str[idx]
+ if reserved_str.include?(chr)
+ tmp += chr
+ else
+ tmp += "%" + chr.unpack("H*").first.upcase
+ end
+ end
+ #puts "#{str}: #{tmp}"
+ tmp
+ end
end

0 comments on commit 499ccf6

Please sign in to comment.
Something went wrong with that request. Please try again.