Ticket #1456: url_multi_value_fixed2.patch

File url_multi_value_fixed2.patch, 1.9 kB (added by Chris Arndt, 8 months ago)
  • turbogears/controllers.py

    old new  
    513513        else: 
    514514            pairs = [(key, value)] 
    515515        for (k,v) in pairs: 
    516             if isinstance(value, unicode): 
    517                 value = value.encode("utf8") 
     516            if v is None: 
     517                continue 
     518            if isinstance(v, unicode): 
     519                v = v.encode("utf8") 
    518520            args.append("%s=%s" % (k, urllib.quote(str(v)))) 
    519521    if args: 
    520522        result += "?" + "&".join(args) 
  • turbogears/tests/test_controllers.py

    old new  
    584584        assert url("/foo", bar=("asdf","qwer")) in \ 
    585585                ["/foo?bar=qwer&bar=asdf", "/foo?bar=asdf&bar=qwer"] 
    586586 
     587    def test_unicode(self): 
     588        """url() can handle unicode parameters""" 
     589        testutil.create_request("/") 
     590        assert url('/', x=u'\N{LATIN SMALL LETTER A WITH GRAVE}' 
     591            u'\N{LATIN SMALL LETTER E WITH GRAVE}' 
     592            u'\N{LATIN SMALL LETTER I WITH GRAVE}' 
     593            u'\N{LATIN SMALL LETTER O WITH GRAVE}' 
     594            u'\N{LATIN SMALL LETTER U WITH GRAVE}') \ 
     595            == '/?x=%C3%A0%C3%A8%C3%AC%C3%B2%C3%B9' 
     596 
     597    def test_list(self): 
     598        """url can handle list parameters, with unicode too""" 
     599        testutil.create_request("/") 
     600        assert url('/', foo=['bar', u'\N{LATIN SMALL LETTER A WITH GRAVE}']) \ 
     601            == '/?foo=bar&foo=%C3%A0' 
     602 
    587603    def tearDown(self): 
    588604        turbogears.config.update({"server.webpath" : ""}) 
    589605        turbogears.startup.startTurboGears() 
    590606 
     607 
    591608def test_index_trailing_slash(): 
    592609    "If there is no trailing slash on an index method call, redirect" 
    593610    cherrypy.root = SubApp()