misc: unquote brackets in variadic URLs (#7016)
This commit is contained in:
parent
f701116882
commit
7f6972789e
|
@ -79,3 +79,11 @@ def test_url_server_even_more_more():
|
|||
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_path_missing_var():
|
||||
assert get_variadic_url('http://www.example.net/foobar/[path]',
|
||||
{}) == 'http://www.example.net/foobar/[path]'
|
||||
|
||||
def test_url_base_and_missing_var():
|
||||
assert get_variadic_url('[url]/foobar/[path]',
|
||||
{'url': 'http://www.example.net'}) == 'http://www.example.net/foobar/[path]'
|
||||
|
|
|
@ -295,6 +295,11 @@ def get_variadic_url(url, variables, encode_query=True):
|
|||
tmpl.generate(fd, variables)
|
||||
return fd.getvalue()
|
||||
|
||||
def partial_quote(string):
|
||||
# unquote brackets, as there may be further processing that needs them
|
||||
# intact.
|
||||
return quote(string).replace('%5B', '[').replace('%5D', ']')
|
||||
|
||||
p = urlparse.urlsplit(url)
|
||||
scheme, netloc, path, query, fragment = \
|
||||
p.scheme, p.netloc, p.path, p.query, p.fragment
|
||||
|
@ -325,9 +330,9 @@ def get_variadic_url(url, variables, encode_query=True):
|
|||
if p2.path and not path:
|
||||
path, query = p2.path, p2.query
|
||||
if path:
|
||||
path = quote(ezt_substitute(path, variables))
|
||||
path = partial_quote(ezt_substitute(path, variables))
|
||||
if fragment and '[' in fragment:
|
||||
fragment = quote(ezt_substitute(fragment, variables))
|
||||
fragment = partial_quote(ezt_substitute(fragment, variables))
|
||||
if query and '[' in query:
|
||||
p_qs = urlparse.parse_qsl(query)
|
||||
if len(p_qs) == 0:
|
||||
|
|
Loading…
Reference in New Issue