# HG changeset patch # User Micha¸«³l Cadilhac # Date 1189597702 0 # Node ID c431e16c163546036155c0a735a9c05db7248df7 # Parent 8418c42a78543374b563bcb4f36dd7eb48b62d6c (browse-url-encode-url): Fix an infinite loop. New argument `filename-p' to use one set of confusing chars or another. (browse-url-file-url): Use the argument. Suggested by Johannes Weiner. diff -r 8418c42a7854 -r c431e16c1635 lisp/net/browse-url.el --- a/lisp/net/browse-url.el Wed Sep 12 11:33:02 2007 +0000 +++ b/lisp/net/browse-url.el Wed Sep 12 11:48:22 2007 +0000 @@ -619,16 +619,19 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; URL encoding -(defun browse-url-encode-url (url) - "Encode all `confusing' characters in URL." - (let ((encoded-url (copy-sequence url))) - (while (string-match "%" encoded-url) - (setq encoded-url (replace-match "%25" t t encoded-url))) - (while (string-match "[*\"()',=;? ]" encoded-url) +(defun browse-url-encode-url (url &optional filename-p) + "Encode all `confusing' characters in URL. +If FILENAME-P is nil, the confusing characters are [,)$]. +Otherwise, the confusing characters are [*\"()',=;?% ]." + (let ((conf-char (if filename-p "[*\"()',=;?% ]" "[,)$]")) + (encoded-url (copy-sequence url)) + (s 0)) + (while (setq s (string-match conf-char encoded-url s)) (setq encoded-url (replace-match (format "%%%x" (string-to-char (match-string 0 encoded-url))) - t t encoded-url))) + t t encoded-url) + s (1+ s))) encoded-url)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -703,7 +706,7 @@ (or file-name-coding-system default-file-name-coding-system)))) (if coding (setq file (encode-coding-string file coding)))) - (setq file (browse-url-encode-url file)) + (setq file (browse-url-encode-url file 'url-is-filename)) (dolist (map browse-url-filename-alist) (when (and map (string-match (car map) file)) (setq file (replace-match (cdr map) t nil file))))