Question about KUrl::equals/cmp...
David Faure
faure at kde.org
Thu Nov 5 10:17:01 GMT 2009
On Wednesday 04 November 2009, Dawit A. wrote:
> On Wednesday 04 November 2009 10:34:25 David Faure wrote:
> > On Wednesday 04 November 2009, Dawit A. wrote:
> > > Is there a reason why KUrl::equals with its second parameter set to
> > > KUrl::CompareWithoutTrailingSlash or KUrl::cmp's second parameter set
> > > to true returns "http://www.kde.org/" and "http://www.kde.org" are not
> > > equal to each other ?
> >
> > Ah, I think I know. Tricky: with http these urls are equal, while with
> > e.g. FTP they are not, since ftp://user@host redirects to
> > ftp://user@host/home/user (on a linux server), while ftp://user@host/ is
> > the root dir. Basically we treat "no path" as "please go to the default
> > starting directory". But I'm ok with an exception for HTTP, where indeed
> > people expect these two urls to be the same.
>
> Well I complely understand the different requirements of different
> protocols, but why would one specificy the
> KUrl::CompareWithoutTrailingSlash flag to make comparisons, like the ftp
> case you mentioned above, when the trailing slash is important ? In other
> words, why use the KUrl::CompareWithoutTrailingSlash flag in the first
> place in such circumstances ?
KDirLister doesn't know about the "no path special case". It simply wants to
know that, when it's told about /foo/bar/, and it knows about /foo/bar, they
are the same item. So KDirLister does all directory-url comparisons with
"CompareWithoutTrailingSlash". Well, technically it uses more often
adjustPath(removeTrailingSlash), but same idea: that one also doesn't remove
the single slash in case the path is just a '/'.
I gave FTP as an example above, now let me give "file" as an example.
Would you say that the local path "/" is equal to the local path ""? I would
say no. The first one is the root dir, the second one is an empty path (which
in the case of local files, doesn't represent any file or directory).
I think they are equivalent only for protocols that don't know anything about
directories, like http :-). (But in kde4 we moved away from making KUrl depend
on KProtocolInfo, so no way to write generic solutions like the previous
sentence.)
> It does not seem the correct thing to do to make exceptions in the API for
> a protocol specific need it already accomodates through existing options
> unless of course I am completely missing something. Perhaps not breaking
> existing applications that rely on the current behavior ?
Well, it would not seem correct to have to make exceptions in KDirLister and
other places which compare paths often :-)
I'm a bit surprised that this comes up only now. What do you need this
comparison for, and how is the same problem handled in the current khtml/konq
code? (explicit check for empty path (on http) and making it "/", iirc,
somewhere?)
--
David Faure, faure at kde.org, http://www.davidfaure.fr
Sponsored by Nokia to work on KDE, incl. Konqueror (http://www.konqueror.org).
More information about the kde-core-devel
mailing list