[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#8706: 24.0.50; [PATCH] Function to build a URL query-string
From: |
Ted Zlatanov |
Subject: |
bug#8706: 24.0.50; [PATCH] Function to build a URL query-string |
Date: |
Mon, 23 May 2011 09:36:12 -0500 |
User-agent: |
Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.50 (gnu/linux) |
On Fri, 20 May 2011 11:37:45 -0700 Ian Eure <ian@simplegeo.com> wrote:
IE> This patch adds a url-build-query-string method, which performs the
IE> opposite job of url-parse-query-string. I find myself needing this
IE> method in many projects, and having it in url-util.el seems
IE> beneficial.
I think this is useful.
IE> + (c-concat-separated
IE> + (mapcar (lambda (pair) (apply 'format "%s=%s" pair)) query) "&"))
I would use `mapconcat' (it's what `c-concat-separated' uses under the
hood anyhow).
Also `format' errors out if it doesn't have enough arguments and it's
legitimate to build a URL query like "url?x;y;z" where x, y, and z don't
have values. So I would change the lambda to (untested):
(lambda (pair)
(if (nth 1 pair)
(apply 'format "%s=%s" pair)
(format "%s" (car-safe pair))))
This also handles the case where `pair' is nil by design or by accident.
Finally, the key and the value should be URL-encoded. Do you assume
that will be done before the function is called?
Thanks
Ted