Ticket #1456 (closed defect: fixed)

Opened 10 months ago

Last modified 6 months ago

[PATCH] url allow key with multiple values

Reported by: imix Assigned to: anonymous
Priority: normal Milestone: 1.0.4
Component: TurboGears Version: 1.0.3
Severity: normal Keywords:
Cc:

Description

This patch modifies the url function (in controllers.py) so that it is possible to create an url with multiple values for the same key. This is done by using a list or a tuple as value for a key.

see also: http://groups.google.com/group/turbogears/browse_thread/thread/b832b03cecd3c53e

Attachments

url_multi_value.patch (1.9 kB) - added by imix on 07/26/07 12:05:08.
url_multi_value_fixed.patch (1.6 kB) - added by imix on 11/01/07 12:16:45.
url_multi_value_fixed2.patch (1.9 kB) - added by Chris Arndt on 11/24/07 19:48:40.

Change History

07/26/07 12:05:08 changed by imix

  • attachment url_multi_value.patch added.

07/26/07 16:57:20 changed by Chris Arndt

  • status changed from new to closed.
  • resolution set to fixed.

Applied in r3383 and r3385. Thanks!

10/31/07 13:06:16 changed by volvox

  • status changed from closed to reopened.
  • resolution deleted.

This patch breaks with multiple unicode parameters. Can you add a test too, this time?

I suggest this change

         else:
             pairs = [(key, value)]
         for (k,v) in pairs:
-            if isinstance(value, unicode):
-                value = value.encode("utf8")
+            if isinstance(v, unicode):
+                v = v.encode("utf8")
             args.append("%s=%s" % (k, urllib.quote(str(v))))
     if args:
         result += "?" + "&".join(args)

I am also using this test

class UrlTest(unittest.TestCase):

    def test_unicode(self):
        "tg.url can handle unicode parameters"
        assert tg.url('/',x=
            u'\N{LATIN SMALL LETTER A WITH GRAVE}'+
            u'\N{LATIN SMALL LETTER E WITH GRAVE}'+
            u'\N{LATIN SMALL LETTER I WITH GRAVE}'+
            u'\N{LATIN SMALL LETTER O WITH GRAVE}'+
            u'\N{LATIN SMALL LETTER U WITH GRAVE}') == '/?x=%C3%A0%C3%A8%C3%AC%C3%B2%C3%B9'

    def test_list(self):
        "tg.url can handle list parameters, with unicode too"
        assert tg.url('/',foo=['bar', u'\N{LATIN SMALL LETTER A WITH GRAVE}']) == '/?foo=bar&foo=%C3%A0'

11/01/07 12:16:45 changed by imix

  • attachment url_multi_value_fixed.patch added.

11/01/07 12:18:25 changed by imix

  • type changed from enhancement to defect.

indeed, i (obviously) missed this bug. This new patch (url_multi_value_fixed.patch) includes your fixes and the tests. Thanks

11/24/07 19:28:59 changed by Chris Arndt

Added new patch with fixed testcases.

11/24/07 19:48:40 changed by Chris Arndt

  • attachment url_multi_value_fixed2.patch added.

11/24/07 19:58:28 changed by Chris Arndt

  • status changed from reopened to closed.
  • resolution set to fixed.

Applied in r3755 and r3753/3754/r3756. Thanks!