δΊ 2011-3-1 20:44, Chris Hegarty ει: > 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. > (I am not sure but it seems the mail was not sent successfully - sorry if you receive it twice!) Thanks Chris. I see the bug 7023363 online. I wonder is there a fix now? I find that we may add an else block at the end of the URI.appendAuthority() to throw the right exception:
sb.append(quote(doquote, L_REG_NAME | L_SERVER, H_REG_NAME | H_SERVER)); + } else { + // there is no valid address in "[]" + throw new URISyntaxException(authority, + "Malformed IPv6 address."); } } else { sb.append(quote(authority, Any ideas? > -Chris. > >> Any comments? >> -- Best Regards, Jimmy, Jing LV