Skip to contentSkip to conversation

fetch2: handle empty elements in _param_str_split

PATCH New Ross Burton 1 participant 2 messages Jan 21, 2021

lore
Share & tools
lore
#0 lore raw

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.

---
 bitbake/lib/bb/fetch2/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/lib/bb/fetch2/__init__.py +1 -1
index 07b7ae41b4..ee3d7b1672 100644
@@ -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
#1 lore raw

PATCH 2/2 tests/fetch: add test for empty query parameters

To exercise the previous patch, add a test case.

---
 bitbake/lib/bb/tests/fetch.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
bitbake/lib/bb/tests/fetch.py +19 -0
index 1452d76151..20beab3855 100644
@@ -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