Patches: Browse | Submit New | Admin

[#11230] Test uri.rb against RFC 3986

Date:
2007-05-30 14:16
Priority:
3
Submitted By:
Daniel Martin (fizbin)
Assigned To:
Akinori MUSHA (knu)
Category:
None
State:
Open
Summary:
Test uri.rb against RFC 3986

Detailed description
For more context, see ruby-talk messages 252052, 252096, 252116, 252135, 252146, and 252151.

Basically, uri.rb is written to the URI specification in RFC 2396, but the current URI specification is RFC 3986, and
there are some differences, specifically with regard to how relative URIs get resolved.

This patch *DOES NOT* fix uri.rb.  Instead, this patch is for a new test file which covers all the test cases for relative
URI resolution in RFC 3986.  With the current uri.rb, this test fails; that's the point.  Hopefully, adding a test that
fails with the current bugs will encourage those bugs to get fixed and bring uri.rb into compliance.

Without further ado, the test file:

#! /usr/bin/env ruby
# This is test only of the merge method based on the cases in the text
# of RFC 3986, section 5.4.  The test cases were cut-and-pasted
# directly to reduce the chance of transcription error.

require 'test/unit'
require 'uri'
require 'enumerator'

module URI
    class TestGenericMerge < Test::Unit::TestCase
        def setup
            @url = 'http://a/b/c/d;p?q'
            @base_url = URI.parse(@url)
        end
        def test_merge
            testcases = %w[
      "g:h"           =  "g:h"
      "g"             =  "http://a/b/c/g"
      "./g"           =  "http://a/b/c/g"
      "g/"            =  "http://a/b/c/g/"
      "/g"            =  "http://a/g"
      "//g"           =  "http://g"
      "?y"            =  "http://a/b/c/d;p?y"
      "g?y"           =  "http://a/b/c/g?y"
      "#s"            =  "http://a/b/c/d;p?q#s"
      "g#s"           =  "http://a/b/c/g#s"
      "g?y#s"         =  "http://a/b/c/g?y#s"
      ";x"            =  "http://a/b/c/;x"
      "g;x"           =  "http://a/b/c/g;x"
      "g;x?y#s"       =  "http://a/b/c/g;x?y#s"

      ""              =  "http://a/b/c/d;p?q"
      "."             =  "http://a/b/c/"
      "./"            =  "http://a/b/c/"
      ".."            =  "http://a/b/"
      "../"           =  "http://a/b/"
      "../g"          =  "http://a/b/g"
      "../.."         =  "http://a/"
      "../../"        =  "http://a/"
      "../../g"       =  "http://a/g"
      
      "../../../g"    =  "http://a/g"
      "../../../../g" =  "http://a/g"
      
      "/./g"          =  "http://a/g"
      "/../g"         =  "http://a/g"
      "g."            =  "http://a/b/c/g."
      ".g"            =  "http://a/b/c/.g"
      "g.."           =  "http://a/b/c/g.."
      "..g"           =  "http://a/b/c/..g"
      
      "./../g"        =  "http://a/b/g"
      "./g/."         =  "http://a/b/c/g/"
      "g/./h"         =  "http://a/b/c/g/h"
      "g/../h"        =  "http://a/b/c/h"
      "g;x=1/./y"     =  "http://a/b/c/g;x=1/y"
      "g;x=1/../y"    =  "http://a/b/c/y"
      
      "g?y/./x"       =  "http://a/b/c/g?y/./x"
      "g?y/../x"      =  "http://a/b/c/g?y/../x"
      "g#s/./x"       =  "http://a/b/c/g#s/./x"
      "g#s/../x"      =  "http://a/b/c/g#s/../x"
      
      "http:g"        =  "http:g"
            ]
            testcases.each_slice(3) { |rel, eq, expected|
                rel.gsub!(/"/,'')
                expected.gsub!(/"/,'')
                assert_equal(expected, @base_url.merge(rel).to_s, rel)
            }
        end
    end
end

__END__

Add A Comment: Notepad

Please login


Followup

No Followups Have Been Posted

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

Field Old Value Date By
assigned_tonone2007-06-13 06:30zenspider