$url->path
Gisle Aas (aas@a.sn.no)
Wed, 7 Feb 1996 16:40:33 +0100
I am now mostly happy with the current URI::URL interface, but I have
a bad feeling about the behaviour of the path() and epath() methods
and how they are treating the leading slash.
You will find this comment in the code (_generic.pm)
# 2.4.6
#
# RFC 1738 says:
#
# Note that the "/" between the host (or port) and the
# url-path is NOT part of the url-path.
#
# however, RFC 1808, 2.4.6. says:
#
# Even though the initial slash is not part of the URL path,
# the parser must remember whether or not it was present so
# that later processes can differentiate between relative
# and absolute paths. Often this is done by simply storing
# he preceding slash along with the path.
#
# so we'll store it in $self->{path}, and strip it when asked
# for $self->path(). You can test examine if this "/" is
# present by calling the $url->absolute_path method.
Can anybody explain the rationale behind stating that "/" is *NOT*
part of the path?
In 5b7 we store the leading "/" but we remove it for the value
returned by e?path(). When setting the path value through these
methods we just store the argument value as it is.
This means that:
$u = new URI::URL 'file:/file/xxx/';
$u->path($u->path);
print $u; # prints 'file:file/xxx/'
will loose the leading "/" in the path. It should not have to be like
this :-(
What can we do about it:
1) make e?path() return the leading "/"
2) store the leading "/" as a separate field in the URL
($url->{'absolute_path'}) and provide a separate method to get/set
this value. Also note that a path is always absolute if 'netloc'
is present.
3) make e?path() remove leading "/" from the argument (when setting
a value) How do we make a path absolute then?
4) something else.
I am thinking about doing 1), but perhaps only for epath() since this
should not break old code.
We have the same problem with the path_components() interface
(introduced in 5b7). It is currently not possible to set an absolute
path, but we could define:
$u->path_components("", "file", "xxx"); # to mean just that
Any advice?
--Gisle