summaryrefslogtreecommitdiff
path: root/cinderclient/utils.py
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-10-03 17:54:19 +0000
committerGerrit Code Review <review@openstack.org>2018-10-03 17:54:19 +0000
commit4e17e1d1912f1902a37e4db543e38cdbe3961358 (patch)
treec3f4c33af4f194810620b9c90d8dcdeb3bd82454 /cinderclient/utils.py
parentc73844df2dc1c02637235babb22cd263eaa45a5b (diff)
parent223d754f6162d87a305bcb2b041a5e73d5fae303 (diff)
downloadpython-cinderclient-4.1.0.tar.gz
Merge "Fix encoding of query parameters"4.1.0
Diffstat (limited to 'cinderclient/utils.py')
-rw-r--r--cinderclient/utils.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/cinderclient/utils.py b/cinderclient/utils.py
index f9af58d..28c458d 100644
--- a/cinderclient/utils.py
+++ b/cinderclient/utils.py
@@ -206,15 +206,27 @@ def unicode_key_value_to_string(src):
def build_query_param(params, sort=False):
"""parse list to url query parameters"""
- if params is None:
- params = {}
+ if not params:
+ return ""
+
if not sort:
param_list = list(params.items())
else:
param_list = list(sorted(params.items()))
query_string = parse.urlencode(
- [(k, v) for (k, v) in param_list if v])
+ [(k, v) for (k, v) in param_list if v not in (None, '')])
+
+ # urllib's parse library used to adhere to RFC 2396 until
+ # python 3.7. The library moved from RFC 2396 to RFC 3986
+ # for quoting URL strings in python 3.7 and '~' is now
+ # included in the set of reserved characters. [1]
+ #
+ # Below ensures "~" is never encoded. See LP 1784728 [2] for more details.
+ # [1] https://docs.python.org/3/library/urllib.parse.html#url-quoting
+ # [2] https://bugs.launchpad.net/python-cinderclient/+bug/1784728
+ query_string = query_string.replace("%7E=", "~=")
+
if query_string:
query_string = "?%s" % (query_string,)