From: Ben Darnell Date: Sun, 29 May 2011 01:24:07 +0000 (-0700) Subject: Don't add an extra delimter when no arguments are given X-Git-Tag: v2.0.0~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=155c20fe890e1a71323ab8ac966f69027a512b0f;p=thirdparty%2Ftornado.git Don't add an extra delimter when no arguments are given --- diff --git a/tornado/httputil.py b/tornado/httputil.py index b33ea33e9..04a21fbc0 100644 --- a/tornado/httputil.py +++ b/tornado/httputil.py @@ -156,6 +156,7 @@ def url_concat(url, args): >>> url_concat("http://example.com/foo?a=b", dict(c="d")) 'http://example.com/foo?a=b&c=d' """ + if not args: return url if url[-1] not in ('?', '&'): url += '&' if ('?' in url) else '?' return url + urllib.urlencode(args) diff --git a/tornado/test/httputil_test.py b/tornado/test/httputil_test.py index abad065e0..d73295958 100644 --- a/tornado/test/httputil_test.py +++ b/tornado/test/httputil_test.py @@ -47,3 +47,10 @@ class TestUrlConcat(unittest.TestCase): {'y':'y', 'z':'z'}, ) self.assertEqual(url, "https://localhost/path?a=1&b=2&y=y&z=z") + + def test_url_concat_no_params(self): + url = url_concat( + "https://localhost/path?r=1&t=2", + {}, + ) + self.assertEqual(url, "https://localhost/path?r=1&t=2")