From: Ian Eure <ian@simplegeo.com>
To: Ted Zlatanov <tzz@lifelogs.com>
Cc: 8706@debbugs.gnu.org
Subject: bug#8706: 24.0.50; [PATCH] Function to build a URL query-string
Date: Tue, 7 Jun 2011 10:07:40 -0700 [thread overview]
Message-ID: <70084BE3-710F-47B6-8949-B420F5BF47B4@simplegeo.com> (raw)
In-Reply-To: <87y61uldyj.fsf@lifelogs.com>
Apologies for the late response, I got distracted by other things.
On May 25, 2011, at 1:31 PM, Ted Zlatanov wrote:
> On Wed, 25 May 2011 09:32:15 -0700 Ian Eure <ian@simplegeo.com> wrote:
>
> IE> 1. Two-element sequences should work as they do now.
> IE> 2. One-element sequences should get an empty string appended.
> IE> 3. Invalid sequences ignored.
>
> IE> I'm not sure it makes sense to support #2, since it seems somewhat
> IE> opaque and you can do the same thing with an empty string in scenario
> IE> #1.
>
> Single-element parameters, shown as just "key" instead of "key=val", are
> a well-known URL query string convention. They are not opaque. I think
> they should be explicitly supported.
>
As I said, they _are_ supported. You just have to explicitly pass an empty string in the pair:
(url-build-query-string '(("a" "b") ("c" "")) -> "a=b&c="
I believe this is the correct behavior. It's also precisely what url-parse-query-string returns:
(url-parse-query-string "a=b&c=") -> (("c" "") ("a" "b"))
This is also relevant to Stefan's comment. All else being equal, I think we should support the same conventions it does. The one issue I discovered is how it handles sending multiple values for the same key. Given "a=one&a=two", it returns: (("a" "one" "two")), which my previous iterations don't know what to do with.
Here's an updated patch which should correctly support everything url-parse-query-string produces. I also updated it to allow empty keys, as this was fairly easy with the code refactored to support (key val val val) syntax.
Updated patch:
--- url-util.el.orig 2011-06-07 09:56:36.000000000 -0700
+++ url-util.el 2011-06-07 10:06:09.000000000 -0700
@@ -281,6 +281,31 @@
(setq retval (cons (list key val) retval)))))
retval))
+;;;###autoload
+(defun url-build-query-string (query)
+ "Build a query-string.
+
+Given a QUERY in the form:
+'((key1 val1)
+ (key2 val2)
+ (key3 val1 val2))
+
+\(This is the same format as produced by `url-parse-query-string')
+
+This will return a string
+`key1=val1&key2=val2&key3=val1&key3=val2'. Keys may be strings or
+symbols; if they are symbols, the string name will be used."
+
+ (mapconcat
+ (lambda (key-vals)
+ (let ((escaped
+ (mapcar (lambda (sym)
+ (url-hexify-string (format "%s" sym))) key-vals)))
+
+ (mapconcat (lambda (val) (format "%s=%s" (car escaped) val))
+ (or (cdr escaped) '("")) "&")))
+ query "&"))
+
(defun url-unhex (x)
(if (> x ?9)
(if (>= x ?a)
next prev parent reply other threads:[~2011-06-07 17:07 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-20 18:37 bug#8706: 24.0.50; [PATCH] Function to build a URL query-string Ian Eure
2011-05-23 14:36 ` Ted Zlatanov
[not found] ` <87zkmaopfs.fsf@lifelogs.com>
2011-05-25 16:32 ` Ian Eure
2011-05-25 20:31 ` Ted Zlatanov
2011-06-07 17:07 ` Ian Eure [this message]
2011-06-07 18:12 ` Stefan Monnier
2011-06-07 18:58 ` Ted Zlatanov
2011-06-11 1:15 ` Ted Zlatanov
2011-06-11 6:32 ` Deniz Dogan
2011-06-11 10:29 ` Ted Zlatanov
2011-06-14 1:15 ` Ted Zlatanov
2011-06-14 1:29 ` Ian Eure
2011-06-14 16:14 ` Glenn Morris
2011-06-14 16:27 ` Glenn Morris
2011-06-14 16:56 ` Ted Zlatanov
2011-06-14 16:57 ` Ian Eure
2012-04-12 19:31 ` Lars Magne Ingebrigtsen
2012-04-12 19:34 ` Lars Magne Ingebrigtsen
2012-04-15 23:51 ` Ted Zlatanov
2012-04-16 0:58 ` Glenn Morris
2012-04-18 22:37 ` Glenn Morris
2012-05-13 19:31 ` Lars Magne Ingebrigtsen
2012-05-15 8:54 ` Ted Zlatanov
2011-05-26 0:02 ` Stefan Monnier
2011-05-26 14:33 ` Ted Zlatanov
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=70084BE3-710F-47B6-8949-B420F5BF47B4@simplegeo.com \
--to=ian@simplegeo.com \
--cc=8706@debbugs.gnu.org \
--cc=tzz@lifelogs.com \
/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.