From: Daniel Martin Date: 2007-05-19T04:03:13+09:00 Subject: Re: URI::merge bug? Daniel Martin writes: > RFC 3986 updates the test cases, including them in section 5.4 (Not > in an appendix as RFC 2396 did) That test case is mentioned, and the > behavior is indeed what it looks like from the pseudocode. > > We should probably check that ruby's uri module passes all the tests > now in RFC 3986. If I have a chance I'll go do that. I've converted all the test examples in that section of RFC 3986 into test code; see below. And even with Nakada-san's patch, there's still a problem or two with our resolver relative to the RFC 3986 test cases. However, with that patch it passes everything labeled in the RFC as "Normal Cases" (section 5.4.1). It still has issues with the abnormal cases of section 5.4.2 #! /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__ -- s=%q( Daniel Martin -- martin@snowplow.org puts "s=%q(#{s})",s.to_a.last ) puts "s=%q(#{s})",s.to_a.last