Subject: Re: bug#6339: url-filename => "/c:/some/file.txt"

From: Juanma Barranquero <[email-masked]>
Date: Mon, 26 Jul 2010 13:50:09 +0200

On Thu, Jun 3, 2010 at 04:38, Lennart Borgman <[email-masked]> wrote:

> (setq x (url-generic-parse-url "file:///c:/some/file.txt"))
> (url-filename x) => "/c:/some/file.txt"
>
> Should not that be "c:/some/file.txt"?

This is caused by url-generic-parse-url thinking that in
file://HOST/PATH, the path is /PATH, when in fact, according to the
relevant RFCs, "/" is a separator and part of the URI syntax, and PATH
is an absolute path (to be interpreted as starting from / on Unix, but
that's irrelevant). This was extensively discussed in bug#5345.

The subyacent cause of the bug, IMHO, is that many software for POSIX
environments that parses URIs just takes the /PATH part as a whole
because it is easier than removing the slash and then re-adding it.
That breaks on Windows file: URIs, as this bug, and #5345, show.

So the right fix IMO is as simple as the attached patch. The problem
is that it will likely cause trouble for other users of
url-generic-parse-url which wrongly assume that the path part will be
rooted at /.

Another, hacky & ugly, fix is removing the slash only if the PATH part
matches /[A-Z]:.

I'd rather fix it the good way and watch the fireworks.

    Juanma

=== modified file 'lisp/url/url-parse.el'
--- lisp/url/url-parse.el	2010-06-22 16:48:53 +0000
+++ lisp/url/url-parse.el	2010-07-26 11:46:11 +0000
@@ -148,4 +148,5 @@
           ;; 3.3. Path
+	  (when (looking-at "/") (forward-char 1))
           ;; Gross hack to preserve ';' in data URLs
           (setq save-pos (point))