Changeset 5191

Show
Ignore:
Timestamp:
08/21/08 20:33:37 (3 months ago)
Author:
carndt
Message:

Fix #1862 (url() does not handle URLs with existing query string correctly)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/turbogears/controllers.py

    r5145 r5191  
    548548            if isinstance(v, unicode): 
    549549                v = v.encode('utf8') 
    550             args.append('%s=%s' % (k, urllib.quote(str(v)))) 
     550            args.append((k, str(v))) 
    551551    if args: 
    552         tgpath += '?' + '&'.join(args) 
     552        query_string = urllib.urlencode(args, True) 
     553        if '?' in tgpath: 
     554            tgpath += '&' + query_string 
     555        else: 
     556            tgpath += '?' + query_string 
    553557    return tgpath 
    554558 
  • branches/1.0/turbogears/tests/test_controllers.py

    r5145 r5191  
    678678            ) == '/?foo=bar&foo=%C3%A0' 
    679679 
     680    def test_existing_query_string(self): 
     681        """url() can handle URl with existing query string.""" 
     682        testutil.create_request("/") 
     683        test_url = url('/foo', {'first': 1}) 
     684        assert url(test_url, {'second': 2}) == '/foo?first=1&second=2' 
     685 
    680686    def tearDown(self): 
    681687        config.update({"server.webpath": ""})