emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Your last change to browse-url is bogus.


From: Michaël Cadilhac
Subject: Re: Your last change to browse-url is bogus.
Date: Wed, 12 Sep 2007 13:09:57 +0200
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.50 (gnu/linux)

Hi Johannes!

Johannes Weiner <address@hidden> writes:

>> > These use mostly the same argument.  Can't we generalize this?  Would it 
>> > hurt
>> > the callsites if they all would use "[*\"()',=;? ]"?
>> 
>> Yes, it will.  A ``confusing char'' is just something Firefox or others
>> can consider as a URL separator or as a variable or something when the
>> website is passed as an argument to the executable, AFAIU.
>> 
>> `?=*' for example are not usually ``confusing''.  The only place those
>> chars are to be converted is when we browse for a file (thus when `?='
>> don't have their special meanings).
>
> Ah, okay.  So what about an (&optional filename) for this function?
> And if it's true, the character set to be translated is "[*\"()',=;? ]" and
> percent is also encoded.  If ommited (nil), just "[,)$]" will be translated.
>
> How does that sound?

Yeah, it seems like a good idea : I already added encode-percent, which
had this role but didn't integrate the regexps.  But it's true that if
in 2013 a new web-browser adds a special meaning for `*' in its
executable parameter, it'll not hurt to encode it for all the other
web-browsers.

Great, so we're now here :

--- browse-url.el       12 Sep 2007 10:49:04 +0200      1.61
+++ browse-url.el       12 Sep 2007 13:04:52 +0200      
@@ -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))))

-- 
 |   Michaël `Micha' Cadilhac       |   Je veut dire que la loi francaise    |
 |   http://michael.cadilhac.name   |           est overwritable par le      |
 |   JID/MSN:                       |    reglement interieur il me semble.   |
 `----  address@hidden  |          -- ElBarto               -  --'

Attachment: pgp6xjxCe1Pti.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]