hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Moran <mike_mo...@mac.com>
Subject Re: Relative URIs strike again
Date Thu, 30 Jan 2003 09:29:59 GMT

On Wednesday, January 29, 2003, at 08:42 PM, Michael Becke wrote:

> These cases are partially handled as of now.
>
> <a href="">""</a>
> Does not work, but should.  This falls into the case of abnormal URIs 
> according to the RFC.  I think Armando was working on a fix for this.

Btw, here is an example of an empty URI seen more often:
  <FORM action="" method="post">
  ...form contents...
  </FORM>

This is actually quite useful if it is returned by a Servlet as it 
means "submit back to me".

> <a href="#">"#"</a>
> <a href="#anchor">"#anchor"</a>
> Both of these cases work correctly in the most recent code.

But what exactly is the correct behaviour? At least two major browsers 
implement this behaviour in a different way than you would immediately 
expect. This could just be a bug in them, or it could be a legitimate 
ambiguity. To clarify, which of the following do you interpret as the 
correct behaviour?

["base" + "rel" = "abs"]
A:
"http://www.foo.com/foop.html" + "" = "http://www.foo.com/foop.html"
"http://www.foo.com/foop.html" + "#" = "http://www.foo.com/foop.html"

B:
"http://www.foo.com/foop.html" + "" = "http://www.foo.com/foop.html"
"http://www.foo.com/foop.html" + "#" = "http://www.foo.com/foop.html#"

There are more actual possible permutations than A and B but they are 
two likely groups of choices.

I wrote a little snippet[1] to test the URI behaviour and got the 
following:

HttpClient:
"http://www.foo.com/foop.html" + "" = "http://www.foo.com/foop.html"
"http://www.foo.com/foop.html" + "#" = "http://www.foo.com/foop.html"

It would seem that HttpClient is doing A. Note that I just did a cvs 
update right now and didn't apply any patches, so I may have missed 
some code that is pending.

Incidentally, when I tried a relative URI of "#foop" I got the 
following:

"http://www.foo.com/foop.html" + "#foop" = 
"http://www.foo.com/foop.html"

Surely this is incorrect?

This may be due to the fact that the URI class lops off any fragment 
when you construct it eg (new 
URI("http://www.foo.com/foop.html#foop")).toString()
= http://www.foo.com/foop.html
I wrote a small test case for this[2].

Thanks,

[1]: Snippet:
public class URIMain
{
     public static void main(String[] args) throws Exception
     {
	String base = args[0];
	String rel = "";
	if (args.length >= 2) {
	    rel = args[1];
	}
	URI baseURI = new URI(base);
	URI uri = new URI(baseURI, rel);
	System.out.println("\"" + baseURI + "\" + \"" + rel + "\" = \""
			   + uri + "\"");
	System.out.println("\"" + base + "\" + \"" + rel + "\" = \""
			   + uri + "\"");
     }
}

[2]: Test case:
public class TestURI extends TestNoHost {

     ...

     public void testURIConstructorKeepsFrag() throws Exception {
	String origURIWithFrag = "http://www.foo.com/foo#frag";
	URI uri = new URI(origURIWithFrag);
	String asString = uri.toString();
	assertTrue("Doesn't drop fragment"
		   + " expected: \"" + origURIWithFrag + "\""
		   + " actual: \"" + asString + "\"",
		   origURIWithFrag.equals(asString));
     }

     ...
}

-- 
Mike


Mime
View raw message