diff options
author | Michael Olson <mwolson@gnu.org> | 2008-02-15 17:35:00 +0000 |
---|---|---|
committer | Michael Olson <mwolson@gnu.org> | 2008-02-15 17:35:00 +0000 |
commit | 2964c94e715085829002ded00cc9933cf4b2279c (patch) | |
tree | 82f6e5a8dfc384ffad869f5eefe34d1ff3780230 | |
parent | 4ff658089418170cc4628effc3481b6ec0f01dd2 (diff) |
emms-url: Add emms-url-quote-entire function.
Use it to conservatively escape entire URLs.
Make emms-player-mpd use this instead of emms-url-quote.
darcs-hash:20080215173509-1bfb2-de02bb833c0ca4afefa42f232c1278d1c3e155ca.gz
-rw-r--r-- | emms-player-mpd.el | 2 | ||||
-rw-r--r-- | emms-url.el | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/emms-player-mpd.el b/emms-player-mpd.el index 16d035d..c31c48b 100644 --- a/emms-player-mpd.el +++ b/emms-player-mpd.el @@ -758,7 +758,7 @@ Execute CALLBACK with CLOSURE as its first argument when done." (progn (require 'emms-url) (with-temp-buffer - (url-insert-file-contents (emms-url-quote url)) + (url-insert-file-contents (emms-url-quote-entire url)) (emms-http-decode-buffer (current-buffer)) (emms-player-mpd-add-buffer-contents (current-buffer) closure callback))) diff --git a/emms-url.el b/emms-url.el index aee894d..24ae903 100644 --- a/emms-url.el +++ b/emms-url.el @@ -28,6 +28,31 @@ (require 'url) (require 'emms-compat) +(defvar emms-url-specials-entire + '((?\ . "%20") + (?\n . "%0D%0A")) + "*An alist of characters which must be represented specially in URLs. +The transformation is the key of the pair. + +This is used by `emms-url-quote-entire'.") + +(defun emms-url-quote-entire (url) + "Escape specials conservatively in an entire URL. + +The specials to escape are specified by the `emms-url-specials-entire' +variable. + +If you want to escape parts of URLs thoroughly, then use +`emms-url-quote' instead." + (apply (function concat) + (mapcar + (lambda (ch) + (let ((repl (assoc ch emms-url-specials-entire))) + (if (null repl) + (char-to-string ch) + (cdr repl)))) + (append url nil)))) + (defun emms-url-quote (s &optional safe) "Replace special characters in S using the `%xx' escape. This is useful for escaping parts of URLs, but not entire URLs. |