From cd85cd25b4f129225d20d36fa5326e9e57901da0 Mon Sep 17 00:00:00 2001 From: tenderlove Date: Fri, 2 Mar 2012 23:21:17 +0000 Subject: * lib/xmlrpc/client.rb (new2): raises an ArgumentError on bad arguments. * test/xmlrpc/test_client.rb: tests for bad uris git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34883 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ lib/xmlrpc/client.rb | 4 ++-- test/xmlrpc/test_client.rb | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index d6fbea25c5..2bc4fbaa70 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sat Mar 3 08:20:10 2012 Aaron Patterson + + * lib/xmlrpc/client.rb (new2): raises an ArgumentError on bad + arguments. + * test/xmlrpc/test_client.rb: tests for bad uris + Sat Mar 3 08:08:11 2012 Aaron Patterson * lib/xmlrpc/client.rb (new2): fix custom port specification when an diff --git a/lib/xmlrpc/client.rb b/lib/xmlrpc/client.rb index b9d4affeb2..d6495b55c4 100644 --- a/lib/xmlrpc/client.rb +++ b/lib/xmlrpc/client.rb @@ -349,12 +349,12 @@ module XMLRPC when 'http' then port ||= 80 when 'https' then port ||= 443 else - raise "Wrong protocol specified. Only http or https allowed!" + raise ArgumentError, "Wrong protocol specified. Only http or https allowed!" end port = port.to_i else - raise "Wrong URI as parameter!" + raise ArgumentError, "Wrong URI as parameter!" end proxy_host, proxy_port = (proxy || "").split(":") diff --git a/test/xmlrpc/test_client.rb b/test/xmlrpc/test_client.rb index e12391a3ea..353bfc5f88 100644 --- a/test/xmlrpc/test_client.rb +++ b/test/xmlrpc/test_client.rb @@ -98,5 +98,39 @@ module XMLRPC [ user, password, use_ssl, timeout ].each { |x| refute x } end + + def test_new2_no_path + client = FakeClient.new2 'http://example.org' + host, path, port, *rest = client.args + + assert_equal 'example.org', host + assert_nil path + assert port + + rest.each { |x| refute x } + end + + def test_new2_slash_path + client = FakeClient.new2 'http://example.org/' + host, path, port, *rest = client.args + + assert_equal 'example.org', host + assert_equal '/', path + assert port + + rest.each { |x| refute x } + end + + def test_new2_bad_protocol + assert_raises(ArgumentError) do + XMLRPC::Client.new2 'ftp://example.org' + end + end + + def test_new2_bad_uri + assert_raises(ArgumentError) do + XMLRPC::Client.new2 ':::::' + end + end end end -- cgit v1.2.3