summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-05 04:35:28 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-05 04:35:28 +0000
commitc3a750ebee3960f5ee47bcba4e60d8c3585eb843 (patch)
treee4d530fc5ca4a55652fb4d95ae728544f57d051c
parent55148a250101b662fde32919f14afcf2dcdc801d (diff)
* lib/xmlrpc/client.rb, lib/xmlrpc/server.rb: should use
String#bytesize instead of String#size. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32856 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--lib/xmlrpc/client.rb10
-rw-r--r--lib/xmlrpc/server.rb14
-rw-r--r--test/xmlrpc/test_webrick_server.rb5
4 files changed, 22 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index cd4dc4f..70805dd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Aug 5 13:32:43 2011 Shugo Maeda <shugo@ruby-lang.org>
+
+ * lib/xmlrpc/client.rb, lib/xmlrpc/server.rb: should use
+ String#bytesize instead of String#size.
+
Fri Aug 5 12:18:20 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm_eval.c (check_funcall): try respond_to? first if redefined.
diff --git a/lib/xmlrpc/client.rb b/lib/xmlrpc/client.rb
index c09a951..968292b 100644
--- a/lib/xmlrpc/client.rb
+++ b/lib/xmlrpc/client.rb
@@ -501,7 +501,7 @@ module XMLRPC
header = {
"User-Agent" => USER_AGENT,
"Content-Type" => "text/xml; charset=utf-8",
- "Content-Length" => request.size.to_s,
+ "Content-Length" => request.bytesize.to_s,
"Connection" => (async ? "close" : "keep-alive")
}
@@ -559,10 +559,10 @@ module XMLRPC
end
expected = resp["Content-Length"] || "<unknown>"
- if data.nil? or data.size == 0
- raise "Wrong size. Was #{data.size}, should be #{expected}"
- elsif expected != "<unknown>" and expected.to_i != data.size and resp["Transfer-Encoding"].nil?
- raise "Wrong size. Was #{data.size}, should be #{expected}"
+ if data.nil? or data.bytesize == 0
+ raise "Wrong size. Was #{data.bytesize}, should be #{expected}"
+ elsif expected != "<unknown>" and expected.to_i != data.bytesize and resp["Transfer-Encoding"].nil?
+ raise "Wrong size. Was #{data.bytesize}, should be #{expected}"
end
set_cookies = resp.get_fields("Set-Cookie")
diff --git a/lib/xmlrpc/server.rb b/lib/xmlrpc/server.rb
index b7345cd..b721538 100644
--- a/lib/xmlrpc/server.rb
+++ b/lib/xmlrpc/server.rb
@@ -456,7 +456,7 @@ class CGIServer < BasicServer
$stdin.binmode if $stdin.respond_to? :binmode
data = $stdin.read(length)
- http_error(400, "Bad Request") if data.nil? or data.size != length
+ http_error(400, "Bad Request") if data.nil? or data.bytesize != length
http_write(process(data), "Content-type" => "text/xml; charset=utf-8")
}
@@ -487,7 +487,7 @@ class CGIServer < BasicServer
h = {}
header.each {|key, value| h[key.to_s.capitalize] = value}
h['Status'] ||= "200 OK"
- h['Content-length'] ||= body.size.to_s
+ h['Content-length'] ||= body.bytesize.to_s
str = ""
h.each {|key, value| str << "#{key}: #{value}\r\n"}
@@ -531,7 +531,7 @@ class ModRubyServer < BasicServer
@ap.binmode
data = @ap.read(length)
- http_error(400, "Bad Request") if data.nil? or data.size != length
+ http_error(400, "Bad Request") if data.nil? or data.bytesize != length
http_write(process(data), 200, "Content-type" => "text/xml; charset=utf-8")
}
@@ -562,7 +562,7 @@ class ModRubyServer < BasicServer
h = {}
header.each {|key, value| h[key.to_s.capitalize] = value}
h['Status'] ||= "200 OK"
- h['Content-length'] ||= body.size.to_s
+ h['Content-length'] ||= body.bytesize.to_s
h.each {|key, value| @ap.headers_out[key] = value }
@ap.content_type = h["Content-type"]
@@ -751,17 +751,17 @@ class WEBrickServlet < BasicServer
data = request.body
- if data.nil? or data.size != length
+ if data.nil? or data.bytesize != length
raise WEBrick::HTTPStatus::BadRequest
end
resp = process(data)
- if resp.nil? or resp.size <= 0
+ if resp.nil? or resp.bytesize <= 0
raise WEBrick::HTTPStatus::InternalServerError
end
response.status = 200
- response['Content-Length'] = resp.size
+ response['Content-Length'] = resp.bytesize
response['Content-Type'] = "text/xml; charset=utf-8"
response.body = resp
end
diff --git a/test/xmlrpc/test_webrick_server.rb b/test/xmlrpc/test_webrick_server.rb
index d3aa9cd..e53cc96 100644
--- a/test/xmlrpc/test_webrick_server.rb
+++ b/test/xmlrpc/test_webrick_server.rb
@@ -1,3 +1,5 @@
+# coding: utf-8
+
require 'test/unit'
require 'webrick'
require_relative 'webrick_testing'
@@ -125,5 +127,8 @@ class Test_Webrick < Test::Unit::TestCase
ok, param = @s.call2('test.add', 1, 2, 3)
assert_equal false, ok
assert_equal(-99, param.faultCode)
+
+ # multibyte characters
+ assert_equal "あいうえおかきくけこ", @s.call('test.add', "あいうえお", "かきくけこ")
end
end