From: YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
To: michael@cadilhac.name (Michaël Cadilhac)
Cc: hannes@saeurebad.de, emacs-devel@gnu.org
Subject: Re: Your last change to browse-url is bogus.
Date: Mon, 17 Sep 2007 13:40:49 +0900 [thread overview]
Message-ID: <wl4phtc3am.wl%mituharu@math.s.chiba-u.ac.jp> (raw)
In-Reply-To: <87fy1j1orw.fsf@cadilhac.name>
Your point of view is low-level (string operation), and mine is
high-level (URL operation). The problems is that the current
implementation of browse-url-encode-url is neither of them: it looks
like a result of superficial code factoring.
(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)
s (1+ s)))
encoded-url))
It is inappropriate from a high-level view because it is a mixture of
two semantically different operations. Also inappropriate from a
low-level view because it is not general enough and the function name
doesn't represent what it does.
>>>>> On Thu, 13 Sep 2007 00:50:59 +0200, michael@cadilhac.name (Michaël Cadilhac) said:
>>> What would you do?
>>
>> Maybe I would revert browse-url-file-url to the one that doesn't
>> use browse-url-encode-url [...]. Also I would use more explicit
>> and specific name in place of browse-url-encode-url (e.g.,
>> browse-url-escape-confusing-characters).
>> An alternative way would be, as you suggested, to give characters
>> to be escaped as an argument to browse-url-encode-url, but rename
>> the function so it looks like a low-level string operation.
> Well, for now on I'm not sure which one of the possibilities is the
> good one (and I'm getting sleepy :)). If someone has a strong
> feeling about that around here, it'd be nice to hear him!
I propose the combination of above two, which is similar to what Davis
suggested:
1. Add a low-level string replacing function (say,
browse-url-encode-chars-in-string as you mentioned) that takes an
argument representing the characters to be escaped.
2. In browse-url-file-url, directly call the above low-level
function instead of calling browse-url-encode-url.
3. Change browse-url-encode-url so it calls the the low-level
function introduced in 1, and just do one task (URL -> URL).
The difference between direct and indirect calls to the low-level
function comes from whether it is meaningful as a self-contained task
or not. Escaping confusing characters in a URL deserves a specialized
function, but escaping characters in a filename string is just a part
of the conversion from the filename to a URL.
YAMAMOTO Mitsuharu
mituharu@math.s.chiba-u.ac.jp
next prev parent reply other threads:[~2007-09-17 4:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-12 9:13 Your last change to browse-url is bogus Michaël Cadilhac
2007-09-12 10:20 ` Johannes Weiner
2007-09-12 10:38 ` Michaël Cadilhac
2007-09-12 10:49 ` Johannes Weiner
2007-09-12 11:09 ` Michaël Cadilhac
2007-09-12 11:25 ` Johannes Weiner
2007-09-12 11:46 ` Michaël Cadilhac
2007-09-12 12:54 ` YAMAMOTO Mitsuharu
2007-09-12 13:13 ` Michaël Cadilhac
2007-09-12 14:18 ` YAMAMOTO Mitsuharu
2007-09-12 22:50 ` Michaël Cadilhac
2007-09-17 4:40 ` YAMAMOTO Mitsuharu [this message]
2007-09-17 11:52 ` Michaël Cadilhac
2007-09-12 23:29 ` Stephen J. Turnbull
2007-09-13 2:30 ` Stefan Monnier
2007-09-13 18:15 ` Stephen J. Turnbull
2007-09-13 21:44 ` Stefan Monnier
2007-09-13 2:39 ` Davis Herring
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=wl4phtc3am.wl%mituharu@math.s.chiba-u.ac.jp \
--to=mituharu@math.s.chiba-u.ac.jp \
--cc=emacs-devel@gnu.org \
--cc=hannes@saeurebad.de \
--cc=michael@cadilhac.name \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.