Re: URI::URL parsing 'http:path'

Gisle Aas (aas@bergen.sn.no)
02 Jan 1997 11:26:10 +0100


Clinton Wong <clintdw@netcom.com> writes:

> Here's a strange one:
> 
> my $obj = (new URI::URL 'http:stuff.html', 'http://foo.com/')->abs();
> 
> This results in $obj having an absolute URL of 'http:stuff.html'.
> But if you were to reference 'http:stuff.html' from a page on
> foo.com and click on it, Netscape Navigator and lynx both think
> the absolute URL should be: 'http://foo.com/stuff.html'.
> 
> Which one is correct?

The documentation for $url->abs() should explain this:

     $url->abs([$base, [$allow_scheme_in_relative_urls]])
        The abs() method attempts to return a new absolute
        URI::URL object for a given URL.  In order to convert a
        relative URL into an absolute one, a base URL is
        required. You can associate a default base with a URL
        either by passing a base to the new() constructor when a
        URI::URL is created or using the base() method on the
        object later.  Alternatively you can specify a one-off
        base as a parameter to the abs() method.

        Some older parsers used to allow the scheme name to be
        present in the relative URL if it was the same as the
        base URL scheme.  RFC1808 says that this should be
        avoided, but you can enable this old behaviour by passing
        a TRUE value as the second argument to the abs() method.
        The difference is demonstrated by the following examples:

          url("http:foo")->abs("http://host/a/b")     ==>  "http:foo"
          url("http:foo")->abs("http://host/a/b", 1)  ==>  "http:/host/a/foo"

-- 
Gisle Aas                                         <aas@a.sn.no>
Schibsted Nett AS                                 http://www.sn.no/~aas/