Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1456 (closed defect: fixed)

Opened 10 years ago

Last modified 9 years ago

[PATCH] url allow key with multiple values

Reported by: imix Owned by: 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 Download (1.9 KB) - added by imix 10 years ago.
url_multi_value_fixed.patch Download (1.6 KB) - added by imix 9 years ago.
url_multi_value_fixed2.patch Download (1.9 KB) - added by Chris Arndt 9 years ago.

Change History

Changed 10 years ago by imix

comment:1 Changed 10 years ago by Chris Arndt

  • Status changed from new to closed
  • Resolution set to fixed

Applied in r3383 and r3385. Thanks!

comment:2 Changed 9 years ago by volvox

  • Status changed from closed to reopened
  • Resolution fixed 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'

Changed 9 years ago by imix

comment:3 Changed 9 years ago 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

comment:4 Changed 9 years ago by Chris Arndt

Added new patch with fixed testcases.

Changed 9 years ago by Chris Arndt

comment:5 Changed 9 years ago by Chris Arndt

  • Status changed from reopened to closed
  • Resolution set to fixed

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

Note: See TracTickets for help on using tickets.