From 52fa2a00615451e2a118d749ddc6842adfdc5c5a Mon Sep 17 00:00:00 2001 From: Thomas NOEL Date: Fri, 6 Nov 2015 00:03:37 +0100 Subject: [PATCH] fix in variadic URL (#8889) --- tests/test_variadic_url.py | 9 +++++++++ wcs/qommon/misc.py | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/test_variadic_url.py b/tests/test_variadic_url.py index 447bbfd..5d7e33d 100644 --- a/tests/test_variadic_url.py +++ b/tests/test_variadic_url.py @@ -64,6 +64,10 @@ def test_url_server(): assert get_variadic_url('[url]/foobar', {'url': 'http://www.example.net'}) == 'http://www.example.net/foobar' +def test_url_server_qs_without_slash(): + assert get_variadic_url('[url]?foo=bar', + {'url': 'http://www.example.net/'}) == 'http://www.example.net/?foo=bar' + def test_url_server_more(): assert get_variadic_url('[url]/foobar/json?toto', {'url': 'http://www.example.net'}) == 'http://www.example.net/foobar/json?toto' @@ -80,6 +84,11 @@ def test_url_whole_with_qs(): assert get_variadic_url('[url]', {'url': 'http://www.example.net/?foo=bar'}) == 'http://www.example.net/?foo=bar' +def test_url_whole_with_qs_2(): + for url in ('[url]?bar=foo', '[url]&bar=foo', '[url]/?bar=foo'): + assert get_variadic_url(url, {'url': 'http://www.example.net/?foo=bar'}) in \ + ('http://www.example.net/?bar=foo&foo=bar', 'http://www.example.net/?foo=bar&bar=foo') + def test_path_missing_var(): assert get_variadic_url('http://www.example.net/foobar/[path]', {}) == 'http://www.example.net/foobar/[path]' diff --git a/wcs/qommon/misc.py b/wcs/qommon/misc.py index ae7f805..4d6e491 100644 --- a/wcs/qommon/misc.py +++ b/wcs/qommon/misc.py @@ -321,7 +321,11 @@ def get_variadic_url(url, variables, encode_query=True): p2 = urlparse.urlsplit(before_path) scheme, netloc = p2.scheme, p2.netloc if p2.path and not path: - path, query = p2.path, p2.query + path, query2 = p2.path, p2.query + if query and query2: + query += '&' + query2 + else: + query = query or query2 if path: path = partial_quote(ezt_substitute(path, variables)) if fragment and '[' in fragment: -- 2.6.2