From 2964c94e715085829002ded00cc9933cf4b2279c Mon Sep 17 00:00:00 2001 From: Michael Olson Date: Fri, 15 Feb 2008 17:35:00 +0000 Subject: 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 --- emms-player-mpd.el | 2 +- emms-url.el | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) 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. -- cgit v1.2.3