[前][次][番号順一覧][スレッド一覧]

ruby-changes:20898

From: shugo <ko1@a...>
Date: Fri, 12 Aug 2011 17:11:18 +0900 (JST)
Subject: [ruby-changes:20898] shugo:r32947 (ruby_1_9_3): * backport r32856 from trunk.

shugo	2011-08-12 17:06:49 +0900 (Fri, 12 Aug 2011)

  New Revision: 32947

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32947

  Log:
    * backport r32856 from trunk.
    * lib/xmlrpc/client.rb, lib/xmlrpc/server.rb: should use
      String#bytesize instead of String#size.

  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/lib/xmlrpc/client.rb
    branches/ruby_1_9_3/lib/xmlrpc/server.rb
    branches/ruby_1_9_3/test/xmlrpc/test_webrick_server.rb

Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 32946)
+++ ruby_1_9_3/ChangeLog	(revision 32947)
@@ -1,3 +1,10 @@
+Fri Aug  5 13:32:43 2011  Shugo Maeda  <shugo@r...>
+
+	* backport r32856 from trunk.
+
+	* lib/xmlrpc/client.rb, lib/xmlrpc/server.rb: should use
+	  String#bytesize instead of String#size.
+
 Fri Aug 12 13:53:03 2011  Narihiro Nakamura  <narihiro@n...>
 
 	* backport r32894 from trunk.
Index: ruby_1_9_3/lib/xmlrpc/client.rb
===================================================================
--- ruby_1_9_3/lib/xmlrpc/client.rb	(revision 32946)
+++ ruby_1_9_3/lib/xmlrpc/client.rb	(revision 32947)
@@ -501,7 +501,7 @@
       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 @@
       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")
Index: ruby_1_9_3/lib/xmlrpc/server.rb
===================================================================
--- ruby_1_9_3/lib/xmlrpc/server.rb	(revision 32946)
+++ ruby_1_9_3/lib/xmlrpc/server.rb	(revision 32947)
@@ -456,7 +456,7 @@
       $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 @@
     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 @@
       @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 @@
     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 @@
 
     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
Index: ruby_1_9_3/test/xmlrpc/test_webrick_server.rb
===================================================================
--- ruby_1_9_3/test/xmlrpc/test_webrick_server.rb	(revision 32946)
+++ ruby_1_9_3/test/xmlrpc/test_webrick_server.rb	(revision 32947)
@@ -1,3 +1,5 @@
+# coding: utf-8
+
 require 'test/unit'
 require 'webrick'
 require_relative 'webrick_testing'
@@ -124,5 +126,8 @@
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]