Mercurial > emacs
comparison lisp/net/browse-url.el @ 84508:c431e16c1635
(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.
author | Michaël Cadilhac <michael.cadilhac@lrde.org> |
---|---|
date | Wed, 12 Sep 2007 11:48:22 +0000 |
parents | 6a870293225d |
children | 5c69a4b491f6 |
comparison
equal
deleted
inserted
replaced
84507:8418c42a7854 | 84508:c431e16c1635 |
---|---|
617 :group 'browse-url) | 617 :group 'browse-url) |
618 | 618 |
619 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 619 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
620 ;; URL encoding | 620 ;; URL encoding |
621 | 621 |
622 (defun browse-url-encode-url (url) | 622 (defun browse-url-encode-url (url &optional filename-p) |
623 "Encode all `confusing' characters in URL." | 623 "Encode all `confusing' characters in URL. |
624 (let ((encoded-url (copy-sequence url))) | 624 If FILENAME-P is nil, the confusing characters are [,)$]. |
625 (while (string-match "%" encoded-url) | 625 Otherwise, the confusing characters are [*\"()',=;?% ]." |
626 (setq encoded-url (replace-match "%25" t t encoded-url))) | 626 (let ((conf-char (if filename-p "[*\"()',=;?% ]" "[,)$]")) |
627 (while (string-match "[*\"()',=;? ]" encoded-url) | 627 (encoded-url (copy-sequence url)) |
628 (s 0)) | |
629 (while (setq s (string-match conf-char encoded-url s)) | |
628 (setq encoded-url | 630 (setq encoded-url |
629 (replace-match (format "%%%x" | 631 (replace-match (format "%%%x" |
630 (string-to-char (match-string 0 encoded-url))) | 632 (string-to-char (match-string 0 encoded-url))) |
631 t t encoded-url))) | 633 t t encoded-url) |
634 s (1+ s))) | |
632 encoded-url)) | 635 encoded-url)) |
633 | 636 |
634 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 637 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
635 ;; URL input | 638 ;; URL input |
636 | 639 |
701 Use variable `browse-url-filename-alist' to map filenames to URLs." | 704 Use variable `browse-url-filename-alist' to map filenames to URLs." |
702 (let ((coding (and default-enable-multibyte-characters | 705 (let ((coding (and default-enable-multibyte-characters |
703 (or file-name-coding-system | 706 (or file-name-coding-system |
704 default-file-name-coding-system)))) | 707 default-file-name-coding-system)))) |
705 (if coding (setq file (encode-coding-string file coding)))) | 708 (if coding (setq file (encode-coding-string file coding)))) |
706 (setq file (browse-url-encode-url file)) | 709 (setq file (browse-url-encode-url file 'url-is-filename)) |
707 (dolist (map browse-url-filename-alist) | 710 (dolist (map browse-url-filename-alist) |
708 (when (and map (string-match (car map) file)) | 711 (when (and map (string-match (car map) file)) |
709 (setq file (replace-match (cdr map) t nil file)))) | 712 (setq file (replace-match (cdr map) t nil file)))) |
710 file) | 713 file) |
711 | 714 |