GNU bug report logs - #13442
24.1; Please add a function to hexify paths to url-util, e.g. the attached

Previous Next

Package: emacs;

Reported by: Reuben Thomas <rrt <at> sc3d.org>

Date: Mon, 14 Jan 2013 22:31:01 UTC

Severity: wishlist

Found in version 24.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


Message #8 received at 13442 <at> debbugs.gnu.org (full text, mbox):

From: YAMAMOTO Mitsuharu <mituharu <at> math.s.chiba-u.ac.jp>
To: Reuben Thomas <rrt <at> sc3d.org>
Cc: 13442 <at> debbugs.gnu.org
Subject: Re: bug#13442: 24.1;
	Please add a function to hexify paths to url-util, e.g. the attached
Date: Tue, 15 Jan 2013 11:35:10 +0900
>>>>> On Mon, 14 Jan 2013 22:29:20 +0000, Reuben Thomas <rrt <at> sc3d.org> said:

> Sometimes, one needs to escape a path that will be made part of a URL. The code here:
> https://github.com/MassimoLauria/dotemacs/blob/master/init-latex.el

> shows a need for it, namely, escaping a filename to pass as part of a
> URL to DBus as part of the use of SyncTeX.

> As far as I can tell, there's no function that does this currently.
> Something like the code at the above-mentioned URL seems to work nicely,
> e.g.:

> (defun url-hexify-path (path)
>   "Handle special characters for urlify. `/' is added temporarily
> to `url-unreserved-chars', so that `url-hexify-string' won't
> escape path separators."
>   (let ((url-unreserved-chars (cons ?/ url-unreserved-chars)))
>     (url-hexify-string path)))

> though I imagine this could be more neatly done. Since '/' is the only
> special character in paths that needs to be retained in URLs, the
> algorithm seems sound, at least.

I usually do that like this:

;; Suppose we have an absolute file name in `file-name'.
(let* ((coding (or file-name-coding-system
		   default-file-name-coding-system))
       (encoded-file-name (if coding (encode-coding-string file-name coding)
			    file-name)))
  (concat "file://localhost"
	  (mapconcat 'url-hexify-string
		     (split-string encoded-file-name "/") "/")))

BTW, I think it is not a good idea to provide a function that simply
"escapes" a file name string.  Such a function should always return a
well-formed URL.  See also
http://lists.gnu.org/archive/html/emacs-devel/2007-09/msg01168.html
and
http://lists.gnu.org/archive/html/emacs-devel/2006-05/msg01060.html .

				     YAMAMOTO Mitsuharu
				mituharu <at> math.s.chiba-u.ac.jp




This bug report was last modified 9 years and 152 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.