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

ruby-changes:22835

From: tenderlove <ko1@a...>
Date: Sat, 3 Mar 2012 08:46:27 +0900 (JST)
Subject: [ruby-changes:22835] tenderlove:r34884 (trunk): * lib/xmlrpc/client.rb (new2): use URI for uri parsing.

tenderlove	2012-03-03 08:46:17 +0900 (Sat, 03 Mar 2012)

  New Revision: 34884

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

  Log:
    * lib/xmlrpc/client.rb (new2): use URI for uri parsing.
    * test/xmlrpc/test_client.rb: test that query params are passed to the
      client constructor.

  Modified files:
    trunk/ChangeLog
    trunk/lib/xmlrpc/client.rb
    trunk/test/xmlrpc/test_client.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 34883)
+++ ChangeLog	(revision 34884)
@@ -1,3 +1,9 @@
+Sat Mar  3 08:42:25 2012  Aaron Patterson <aaron@t...>
+
+	* lib/xmlrpc/client.rb (new2): use URI for uri parsing.
+	* test/xmlrpc/test_client.rb: test that query params are passed to the
+	  client constructor.
+
 Sat Mar  3 08:20:10 2012  Aaron Patterson <aaron@t...>
 
 	* lib/xmlrpc/client.rb (new2): raises an ArgumentError on bad
Index: lib/xmlrpc/client.rb
===================================================================
--- lib/xmlrpc/client.rb	(revision 34883)
+++ lib/xmlrpc/client.rb	(revision 34884)
@@ -339,24 +339,23 @@
     class << self
 
     def new2(uri, proxy=nil, timeout=nil)
-      if match = /^([^:]+):\/\/(([^@]+)@)?([^\/]+)(\/.*)?$/.match(uri)
-        proto = match[1]
-        user, passwd = (match[3] || "").split(":")
-        host, port = match[4].split(":")
-        path = match[5]
+      begin
+        url = URI(uri)
+      rescue URI::InvalidURIError => e
+        raise ArgumentError, e.message, e.backtrace
+      end
 
-        case proto
-        when 'http'  then port ||= 80
-        when 'https' then port ||= 443
-        else
-          raise ArgumentError, "Wrong protocol specified. Only http or https allowed!"
-        end
-
-        port = port.to_i
-      else
-        raise ArgumentError, "Wrong URI as parameter!"
+      unless URI::HTTP === url
+        raise ArgumentError, "Wrong protocol specified. Only http or https allowed!"
       end
 
+      proto  = url.scheme
+      user   = url.user
+      passwd = url.password
+      host   = url.host
+      port   = url.port
+      path   = url.path.empty? ? nil : url.request_uri
+
       proxy_host, proxy_port = (proxy || "").split(":")
       proxy_port = proxy_port.to_i if proxy_port
 
Index: test/xmlrpc/test_client.rb
===================================================================
--- test/xmlrpc/test_client.rb	(revision 34883)
+++ test/xmlrpc/test_client.rb	(revision 34884)
@@ -132,5 +132,16 @@
         XMLRPC::Client.new2 ':::::'
       end
     end
+
+    def test_new2_path_with_query
+      client = FakeClient.new2 'http://example.org/foo?bar=baz'
+      host, path, port, *rest = client.args
+
+      assert_equal 'example.org', host
+      assert_equal '/foo?bar=baz', path
+      assert port
+
+      rest.each { |x| refute x }
+    end
   end
 end

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

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