unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Johannes Weiner <hannes@saeurebad.de>
To: Emacs development discussions <emacs-devel@gnu.org>
Subject: [PATCH 1/2] browse-url.el: cleanup
Date: Wed, 22 Aug 2007 03:16:41 +0200	[thread overview]
Message-ID: <20070822011641.GB1945@saeurebad.de> (raw)
In-Reply-To: <20070822011418.GA1945@saeurebad.de>

[-- Attachment #1: Type: text/plain, Size: 92 bytes --]

Hi,

this patch moves the common pattern of encoding URLs to a dedicated function.

	Hannes

[-- Attachment #2: emacs-browse-url-cleanup.patch --]
[-- Type: text/x-diff, Size: 4749 bytes --]

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)

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

  reply	other threads:[~2007-08-22  1:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-22  1:14 [PATCH 0/2] browse-url.el: cleanup & elinks support Johannes Weiner
2007-08-22  1:16 ` Johannes Weiner [this message]
2007-08-22  1:35   ` [PATCH 1/2] browse-url.el: cleanup Magnus Henoch
2007-08-22  1:52     ` Johannes Weiner
2007-08-22 21:27   ` Richard Stallman
2007-09-07  4:41     ` Glenn Morris
2007-08-22  1:19 ` [PATCH 2/2] browse-url.el: elinks support Johannes Weiner
2007-08-22 21:27   ` Richard Stallman
2007-09-07  4:40     ` Glenn Morris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070822011641.GB1945@saeurebad.de \
    --to=hannes@saeurebad.de \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).