From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Johannes Weiner Newsgroups: gmane.emacs.devel Subject: [PATCH 1/2] browse-url.el: cleanup Date: Wed, 22 Aug 2007 03:16:41 +0200 Message-ID: <20070822011641.GB1945@saeurebad.de> References: <20070822011418.GA1945@saeurebad.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="WIyZ46R2i8wDzkSu" X-Trace: sea.gmane.org 1187745517 26296 80.91.229.12 (22 Aug 2007 01:18:37 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 22 Aug 2007 01:18:37 +0000 (UTC) To: Emacs development discussions Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Aug 22 03:18:34 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1INerf-0008UY-CS for ged-emacs-devel@m.gmane.org; Wed, 22 Aug 2007 03:18:31 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1INere-0007on-8q for ged-emacs-devel@m.gmane.org; Tue, 21 Aug 2007 21:18:30 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1INeq3-0006WP-77 for emacs-devel@gnu.org; Tue, 21 Aug 2007 21:16:51 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1INeq2-0006W7-Rn for emacs-devel@gnu.org; Tue, 21 Aug 2007 21:16:50 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1INeq2-0006W2-HU for emacs-devel@gnu.org; Tue, 21 Aug 2007 21:16:50 -0400 Original-Received: from saeurebad.de ([85.214.36.134]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1INeq0-0002hT-WD for emacs-devel@gnu.org; Tue, 21 Aug 2007 21:16:50 -0400 Original-Received: by saeurebad.de (Postfix, from userid 1000) id 1E3072F03B2; Wed, 22 Aug 2007 03:16:41 +0200 (CEST) Mail-Followup-To: Emacs development discussions Content-Disposition: inline In-Reply-To: <20070822011418.GA1945@saeurebad.de> User-Agent: Mutt/1.5.16 (2007-06-11) X-Detected-Kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:76923 Archived-At: --WIyZ46R2i8wDzkSu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, this patch moves the common pattern of encoding URLs to a dedicated function. Hannes --WIyZ46R2i8wDzkSu Content-Type: text/x-diff; charset=us-ascii Content-Disposition: inline; filename="emacs-browse-url-cleanup.patch" diff -Naur emacs.orig/lisp/net/browse-url.el emacs/lisp/net/browse-url.el --- emacs.orig/lisp/net/browse-url.el 2007-08-22 02:38:28.000000000 +0200 +++ emacs/lisp/net/browse-url.el 2007-08-22 02:38:53.000000000 +0200 @@ -612,6 +612,21 @@ :group 'browse-url) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; URL encoding + +(defun browse-url-encode-url (url) + "Encode all `confusing' characters in URL." + (let ((encoded-url (copy-seq url))) + (while (string-match "%" encoded-url) + (setq encoded-url (replace-match "%25" t t encoded-url))) + (while (string-match "[*\"()',=;? ]" encoded-url) + (setq encoded-url + (replace-match (format "%%%x" + (string-to-char (match-string 0 encoded-url))) + t t encoded-url))) + encoded-url)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; URL input ;;;###autoload @@ -684,14 +699,7 @@ (or file-name-coding-system default-file-name-coding-system)))) (if coding (setq file (encode-coding-string file coding)))) - ;; URL-encode special chars, do % first - (let ((s 0)) - (while (setq s (string-match "%" file s)) - (setq file (replace-match "%25" t t file) - s (1+ s)))) - (while (string-match "[*\"()',=;? ]" file) - (let ((enc (format "%%%x" (aref file (match-beginning 0))))) - (setq file (replace-match enc t t file)))) + (setq file (browse-url-encode-url file)) (dolist (map browse-url-filename-alist) (when (and map (string-match (car map) file)) (setq file (replace-match (cdr map) t nil file)))) @@ -897,11 +905,7 @@ When called non-interactively, optional second argument NEW-WINDOW is used instead of `browse-url-new-window-flag'." (interactive (browse-url-interactive-arg "URL: ")) - ;; URL encode any `confusing' characters in the URL. This needs to - ;; include at least commas; presumably also close parens and dollars. - (while (string-match "[,)$]" url) - (setq url (replace-match - (format "%%%x" (string-to-char (match-string 0 url))) t t url))) + (setq url (browse-url-encode-url url)) (let* ((process-environment (browse-url-process-environment)) (process (apply 'start-process @@ -971,11 +975,7 @@ When called non-interactively, optional second argument NEW-WINDOW is used instead of `browse-url-new-window-flag'." (interactive (browse-url-interactive-arg "URL: ")) - ;; URL encode any `confusing' characters in the URL. This needs to - ;; include at least commas; presumably also close parens and dollars. - (while (string-match "[,)$]" url) - (setq url (replace-match - (format "%%%x" (string-to-char (match-string 0 url))) t t url))) + (setq url (browse-url-encode-url url)) (let* ((process-environment (browse-url-process-environment)) (process (apply 'start-process @@ -1033,11 +1033,7 @@ are ignored as well. Firefox on Windows will always open the requested URL in a new window." (interactive (browse-url-interactive-arg "URL: ")) - ;; URL encode any `confusing' characters in the URL. This needs to - ;; include at least commas; presumably also close parens. - (while (string-match "[,)]" url) - (setq url (replace-match - (format "%%%x" (string-to-char (match-string 0 url))) t t url))) + (setq url (browse-url-encode-url url)) (let* ((process-environment (browse-url-process-environment)) (process (apply 'start-process @@ -1089,11 +1085,7 @@ When called non-interactively, optional second argument NEW-WINDOW is used instead of `browse-url-new-window-flag'." (interactive (browse-url-interactive-arg "URL: ")) - ;; URL encode any `confusing' characters in the URL. This needs to - ;; include at least commas; presumably also close parens and dollars. - (while (string-match "[,)$]" url) - (setq url (replace-match - (format "%%%x" (string-to-char (match-string 0 url))) t t url))) + (setq url (browse-url-encode-url)) (let* ((process-environment (browse-url-process-environment)) (process (apply 'start-process (concat "galeon " url) @@ -1138,11 +1130,7 @@ When called non-interactively, optional second argument NEW-WINDOW is used instead of `browse-url-new-window-flag'." (interactive (browse-url-interactive-arg "URL: ")) - ;; URL encode any `confusing' characters in the URL. This needs to - ;; include at least commas; presumably also close parens and dollars. - (while (string-match "[,)$]" url) - (setq url (replace-match - (format "%%%x" (string-to-char (match-string 0 url))) t t url))) + (setq url (browse-url-encode-url url)) (let* ((process-environment (browse-url-process-environment)) (process (apply 'start-process (concat "epiphany " url) --WIyZ46R2i8wDzkSu Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --WIyZ46R2i8wDzkSu--