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

ruby-changes:50711

From: nobu <ko1@a...>
Date: Thu, 22 Mar 2018 01:04:02 +0900 (JST)
Subject: [ruby-changes:50711] nobu:r62882 (trunk): Docs and tests on URI.hierarchical?, URI.absolute?

nobu	2018-03-22 01:03:59 +0900 (Thu, 22 Mar 2018)

  New Revision: 62882

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

  Log:
    Docs and tests on URI.hierarchical?, URI.absolute?
    
    Improve code coverage and clarify meaning of hierarchical based on RFC
    text.
    
    [Fix GH-1846]
    
    From: Xavier Riley <xavriley@h...>

  Modified files:
    trunk/lib/uri/generic.rb
    trunk/test/uri/test_generic.rb
Index: test/uri/test_generic.rb
===================================================================
--- test/uri/test_generic.rb	(revision 62881)
+++ test/uri/test_generic.rb	(revision 62882)
@@ -774,6 +774,24 @@ class URI::TestGeneric < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/uri/test_generic.rb#L774
     assert_equal 'http://example', uri.to_s
   end
 
+  def test_hierarchical
+    hierarchical = URI.parse('http://a.b.c/example')
+    opaque = URI.parse('mailto:mduerst@i...')
+
+    assert hierarchical.hierarchical?
+    refute opaque.hierarchical?
+  end
+
+  def test_absolute
+    abs_uri = URI.parse('http://a.b.c/')
+    not_abs = URI.parse('a.b.c')
+
+    refute not_abs.absolute?
+
+    assert abs_uri.absolute
+    assert abs_uri.absolute?
+  end
+
   def test_ipv6
     assert_equal("[::1]", URI("http://[::1]/bar/baz").host)
     assert_equal("::1", URI("http://[::1]/bar/baz").hostname)
Index: lib/uri/generic.rb
===================================================================
--- lib/uri/generic.rb	(revision 62881)
+++ lib/uri/generic.rb	(revision 62882)
@@ -946,7 +946,25 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L946
     end
 
     #
-    # Checks if URI has a path
+    # Returns true if URI is hierarchical
+    #
+    # == Description
+    #
+    # URI has components listed in order of decreashing signficance from left to right
+    # see RFC3986 https://tools.ietf.org/html/rfc3986 1.2.3
+    #
+    # == Usage
+    #
+    #   require 'uri'
+    #
+    #   uri = URI.parse("http://my.example.com/")
+    #   => #<URI::HTTP http://my.example.com/>
+    #   uri.hierarchical?
+    #   # => true
+    #   uri = URI.parse("mailto:joe@e...")
+    #   => #<URI::MailTo mailto:joe@e...>
+    #   uri.hierarchical?
+    #   # => false
     #
     def hierarchical?
       if @path
@@ -957,7 +975,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L975
     end
 
     #
-    # Checks if URI is an absolute one
+    # Returns true if URI has a scheme (e.g. http:// or https://) specified
     #
     def absolute?
       if @scheme
@@ -969,7 +987,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L987
     alias absolute absolute?
 
     #
-    # Checks if URI is relative
+    # Returns true if URI does not have a scheme (e.g. http:// or https://) specified
     #
     def relative?
       !absolute?

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

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