From 155c20fe890e1a71323ab8ac966f69027a512b0f Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sat, 28 May 2011 18:24:07 -0700 Subject: [PATCH] Don't add an extra delimter when no arguments are given --- tornado/httputil.py | 1 + tornado/test/httputil_test.py | 7 +++++++ 2 files changed, 8 insertions(+) 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") -- 2.47.2