fetch2: handle empty elements in _param_str_split
PATCH 1/2 fetch2: handle empty elements in _param_str_split
_param_str_split is used to split ?foo=1;bar=2 into a dictionary, but throws an exception if a lone semicolon is used as the value doesn't split into two items.
Fix by checking that the result of the first split has content.
Signed-off-by Ross Burton <[email protected]>
--- bitbake/lib/bb/fetch2/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/lib/bb/fetch2/__init__.py +1 -1
@@ -290,7 +290,7 @@ class URI(object): def _param_str_split(self, string, elmdelim, kvdelim="="): ret = collections.OrderedDict() - for k, v in [x.split(kvdelim, 1) for x in string.split(elmdelim)]: + for k, v in [x.split(kvdelim, 1) for x in string.split(elmdelim) if x]: ret[k] = v return ret
Signature · 1 line
2.25.1
PATCH 2/2 tests/fetch: add test for empty query parameters
To exercise the previous patch, add a test case.
Signed-off-by Ross Burton <[email protected]>
--- bitbake/lib/bb/tests/fetch.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
bitbake/lib/bb/tests/fetch.py +19 -0
@@ -87,6 +87,25 @@ class URITest(unittest.TestCase): }, 'relative': False }, + # Check that trailing semicolons are handled correctly + "http://www.example.org/index.html?qparam1=qvalue1;param2=value2;" : { + 'uri': 'http://www.example.org/index.html?qparam1=qvalue1;param2=value2', + 'scheme': 'http', + 'hostname': 'www.example.org', + 'port': None, + 'hostport': 'www.example.org', + 'path': '/index.html', + 'userinfo': '', + 'username': '', + 'password': '', + 'params': { + 'param2': 'value2' + }, + 'query': { + 'qparam1': 'qvalue1' + }, + 'relative': False + }, "http://www.example.com:8080/index.html" : { 'uri': 'http://www.example.com:8080/index.html', 'scheme': 'http',
Signature · 1 line
2.25.1