GNU bug report logs - #8706
24.0.50; [PATCH] Function to build a URL query-string

Previous Next

Package: emacs;

Reported by: Ian Eure <ian <at> simplegeo.com>

Date: Fri, 20 May 2011 18:40:02 UTC

Severity: wishlist

Tags: patch

Found in version 24.0.50

Done: Chong Yidong <cyd <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ted Zlatanov <tzz <at> lifelogs.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#8706: 24.0.50; [PATCH] Function to build a URL query-string
Date: Mon, 23 May 2011 09:36:12 -0500
On Fri, 20 May 2011 11:37:45 -0700 Ian Eure <ian <at> 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





This bug report was last modified 13 years and 13 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.