URI ignores invalid ipv6 address while parsing authority
Chris Hegarty
chris.hegarty at oracle.com
Tue Mar 1 04:44:14 PST 2011
On 03/ 1/11 09:58 AM, Jing LV wrote:
> Hello,
>
> According to authority component RFC2396, if host name is a domain name
> there should be no "[" and "]". However if we put a hostname like
> "[www.abc.com]" while creating a URI, it silently accept, no error is
> reported. I suppose this is a bug. A testcase can be found below:
>
> try {
> uri = new URI("ftp", "[www.abc.com]", "/dir1/dir2", "query", "frag");
> } catch (URISyntaxException e) {
> // Expected
> System.out.printf("Should reach here");
> }
>
> And if we print uri.getAuthority() we'll get a null value.
> I think the problem is caused by ipv6 address, which is enclosed with
> "[]", but a normal hostname does not.
This does appear to be strange. appendAuthority will ignore any
authority in square brackets that does not contain a ':' . The internal
string representation of the uri will then parse without failure,
because parseHierarchical allows empty authority component as long as
it's followed by a non-empty path, query component, or fragment component.
I filed CR 7023363: "URI("ftp", "[www.abc.com]", "/dir1/dir2", "query",
"frag") should throw URISyntaxException", for this.
appendAuthority should probably treat [www.abc.com] as a regular
authority and this would them be caught in parseHierarchical and
URISyntaxException thrown.
-Chris.
>
> Any comments?
>
More information about the net-dev
mailing list