]> git.eshelyaron.com Git - emacs.git/commitdiff
(browse-url-encode-url): Fix an infinite loop.
authorMichaël Cadilhac <michael.cadilhac@lrde.org>
Wed, 12 Sep 2007 11:48:34 +0000 (11:48 +0000)
committerMichaël Cadilhac <michael.cadilhac@lrde.org>
Wed, 12 Sep 2007 11:48:34 +0000 (11:48 +0000)
New argument `filename-p' to use one set of confusing chars or another.
(browse-url-file-url): Use the argument.
Suggested by Johannes Weiner.

lisp/ChangeLog
lisp/net/browse-url.el

index f1cfd7a03eae745a92dc0a6929e1339ae7a87eba..c53e17cce310bc6225de00eccee68909f9980255 100644 (file)
@@ -1,3 +1,10 @@
+2007-09-12  Micha\e,Ak\e(Bl Cadilhac  <michael@cadilhac.name>
+
+       * lisp/net/browse-url.el (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.
+
 2007-09-12  Romain Francoise  <romain@orebokech.com>
 
        * cus-start.el (all): Revert 2007-09-08 change.
index d152f2025610ddad0985fbf413ea00552b1108cc..936ca2d422203da4f676d54b8f33caeabf1a1d81 100644 (file)
@@ -619,16 +619,19 @@ down (this *won't* always work)."
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; 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 @@ Use variable `browse-url-filename-alist' to map filenames to URLs."
                     (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))))