The problem is that "google.com" is, in fact, a valid URL; it's just
not a valid absolute URL. Invalid URLs have non-ascii characters in
them, or violate a few of the other specific parsing rules. In this
case, "google.com" is (I think) being interpreted by NSURL as a
relative path with no base URL given.
If you want to know whether you have a fully-formed, absolute URL, try
looking at [[url absoluteURL] scheme]; if this is nil, then you don't
have a well-formed, absolute URL.
Hope that helps,
REW
On Nov 10, 2003, at 3:33 PM, Nick Matsakis wrote:
>
> http://developer.apple.com/documentation/Cocoa/Reference/Foundation/
> ObjC_classic/Classes/NSURL.html#//apple_ref/doc/uid/20000301/BAJBBDIB
>
> I'm stumped. The documentation for NSURL+URLWithString says that if
> the
> string is not well-formed (per RFC 2396) it should return nil.
> However, I
> am not seeing this at all on 10.2.8. Specifically,
>
> ([NSURL URLWithString:@"google.com"] == nil)
>
> evaluates to false. This seems like a bug to me, since well-formed URLs
> should have a scheme, like "http://www.google.com". I suppose
> "google.com" could parse as a relative URL, but in that case I would be
> using NSURL+URLWithString:relativeToURL.
>
> Is this a bug? Is there another way to parse a URL in Cocoa that will
> actually let me know if the URL is valid?
>
> Nick Matsakis
> _______________________________________________
> MacOSX-dev mailing list
> <MacOSX-dev...>
> http://www.omnigroup.com/mailman/listinfo/macosx-dev