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

ruby-changes:35639

From: glass <ko1@a...>
Date: Sat, 27 Sep 2014 12:13:32 +0900 (JST)
Subject: [ruby-changes:35639] glass:r47721 (trunk): * lib/uri/rfc3986_parser.rb: raise URI::InvalidURIError when

glass	2014-09-27 12:13:22 +0900 (Sat, 27 Sep 2014)

  New Revision: 47721

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

  Log:
    * lib/uri/rfc3986_parser.rb: raise URI::InvalidURIError when
      uri doesn't respond to #to_str. [ruby-core:64453] [Bug #10150]
    
    * test/uri/test_parser.rb: test for above.

  Modified files:
    trunk/ChangeLog
    trunk/lib/uri/rfc3986_parser.rb
    trunk/test/uri/test_parser.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47720)
+++ ChangeLog	(revision 47721)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Sep 26 15:03:19 2014  Masaki Matsushita <glass.saga@g...>
+
+	* lib/uri/rfc3986_parser.rb: raise URI::InvalidURIError when
+	  uri doesn't respond to #to_str. [ruby-core:64453] [Bug #10150]
+
+	* test/uri/test_parser.rb: test for above.
+
 Sat Sep 27 10:31:48 2014  Kazuki Tsujimoto  <kazuki@c...>
 
 	* gems/bundled_gems: upgraded to power_assert 0.1.4.
Index: lib/uri/rfc3986_parser.rb
===================================================================
--- lib/uri/rfc3986_parser.rb	(revision 47720)
+++ lib/uri/rfc3986_parser.rb	(revision 47721)
@@ -6,7 +6,11 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/rfc3986_parser.rb#L6
     RFC3986_relative_ref = /\A(?<relative-ref>(?<relative-part>\/\/(?<authority>(?:(?<userinfo>(?:%\h\h|[!$&-.0-;=A-Z_a-z~])*)@)?(?<host>(?<IP-literal>\[(?<IPv6address>(?:\h{1,4}:){6}(?<ls32>\h{1,4}:\h{1,4}|(?<IPv4address>(?<dec-octet>[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]|\d)\.\g<dec-octet>\.\g<dec-octet>\.\g<dec-octet>))|::(?:\h{1,4}:){5}\g<ls32>|\h{1,4}?::(?:\h{1,4}:){4}\g<ls32>|(?:(?:\h{1,4}:){,1}\h{1,4})?::(?:\h{1,4}:){3}\g<ls32>|(?:(?:\h{1,4}:){,2}\h{1,4})?::(?:\h{1,4}:){2}\g<ls32>|(?:(?:\h{1,4}:){,3}\h{1,4})?::\h{1,4}:\g<ls32>|(?:(?:\h{1,4}:){,4}\h{1,4})?::\g<ls32>|(?:(?:\h{1,4}:){,5}\h{1,4})?::\h{1,4}|(?:(?:\h{1,4}:){,6}\h{1,4})?::)|(?<IPvFuture>v\h+\.[!$&-.0-;=A-Z_a-z~]+)\])|\g<IPv4address>|(?<reg-name>(?:%\h\h|[!$&-.0-9;=A-Z_a-z~])+))?(?::(?<port>\d*))?)(?<path-abempty>(?:\/(?<segment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*))*)|(?<path-absolute>\/(?:(?<segment-nz>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])+)(?:\/\g<segment>)*)?)|(?<path-noscheme>(?<segment-nz-nc>(?:%\h\h|[!$&-.0-9;=@-Z_a-z~])+)
 (?:\/\g<segment>)*)|(?<path-empty>))(?:\?(?<query>(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*))?(?:\#(?<fragment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*))?)\z/
 
     def split(uri) #:nodoc:
-      uri = uri.to_str
+      begin
+        uri = uri.to_str
+      rescue NoMethodError
+        raise InvalidURIError, "bad URI(is not URI?): #{uri}"
+      end
       unless uri.ascii_only?
         raise InvalidURIError, "URI must be ascii only #{uri.dump}"
       end
Index: test/uri/test_parser.rb
===================================================================
--- test/uri/test_parser.rb	(revision 47720)
+++ test/uri/test_parser.rb	(revision 47721)
@@ -38,4 +38,10 @@ class URI::TestParser < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/uri/test_parser.rb#L38
     assert_equal(['http', nil, 'a', URI::HTTP.default_port, '/%uDCBA', nil, nil],
 		 uri_to_ary(u1))
   end
+
+  def test_raise_bad_uri_for_integer
+    assert_raise(URI::InvalidURIError) do
+      URI.parse(1)
+    end
+  end
 end

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

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