diff options
| author | Ross Burton <ross.burton@arm.com> | 2024-03-08 06:14:44 -0800 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-03-22 16:26:45 +0000 |
| commit | e20ee877ed41eaf186a108e11ea8fba42490a0e8 (patch) | |
| tree | e023a20b174f88b3414b56df8d1fbc094cbf7552 | |
| parent | adb0ea98d1fbdb2f9d863db1072deba199c0ae0e (diff) | |
| download | poky-e20ee877ed41eaf186a108e11ea8fba42490a0e8.tar.gz | |
bitbake: fetch2: handle URIs with single-valued query parameters
Whilst typically the URI query is a list of key-value pairs, that's not
actually required by the URI specification.
For example: http://example.com/foo?bar is a valid query, but this will
result in the fetcher raising an exception:
File "bitbake/lib/bb/fetch2/__init__.py", line 265, in __init__
self.query = self._param_str_split(urlp.query, "&")
File "bitbake/lib/bb/fetch2/__init__.py", line 293, in _param_str_split
for k, v in [x.split(kvdelim, 1) for x in string.split(elmdelim) if x]:
ValueError: not enough values to unpack (expected 2, got 1)
In this case the query is just "bar", but the fetcher is trying to split
it into a key-value pair.
The URI object exposes the parsed query explicitly as a dictionary of
key-value pairs, so we have to be a little creative here: if a value is
None then it isn't a key-value pair, but a bare key.
Fix this by handling elements without the deliminator in _param_str_split()
(by assigning the value to None), and handle a None value when formatting
the query in _param_str_join().
(Bitbake rev: eac583bd4c46f3bb9661852cb6a1448f16147ff1)
Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | bitbake/lib/bb/fetch2/__init__.py | 4 | ||||
| -rw-r--r-- | bitbake/lib/bb/tests/fetch.py | 15 |
2 files changed, 17 insertions, 2 deletions
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py index 3529531ca1..37fed16e4e 100644 --- a/bitbake/lib/bb/fetch2/__init__.py +++ b/bitbake/lib/bb/fetch2/__init__.py | |||
| @@ -290,12 +290,12 @@ class URI(object): | |||
| 290 | 290 | ||
| 291 | def _param_str_split(self, string, elmdelim, kvdelim="="): | 291 | def _param_str_split(self, string, elmdelim, kvdelim="="): |
| 292 | ret = collections.OrderedDict() | 292 | ret = collections.OrderedDict() |
| 293 | for k, v in [x.split(kvdelim, 1) for x in string.split(elmdelim) if x]: | 293 | for k, v in [x.split(kvdelim, 1) if kvdelim in x else (x, None) for x in string.split(elmdelim) if x]: |
| 294 | ret[k] = v | 294 | ret[k] = v |
| 295 | return ret | 295 | return ret |
| 296 | 296 | ||
| 297 | def _param_str_join(self, dict_, elmdelim, kvdelim="="): | 297 | def _param_str_join(self, dict_, elmdelim, kvdelim="="): |
| 298 | return elmdelim.join([kvdelim.join([k, v]) for k, v in dict_.items()]) | 298 | return elmdelim.join([kvdelim.join([k, v]) if v else k for k, v in dict_.items()]) |
| 299 | 299 | ||
| 300 | @property | 300 | @property |
| 301 | def hostport(self): | 301 | def hostport(self): |
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py index e988e26c0a..85c1f79ff3 100644 --- a/bitbake/lib/bb/tests/fetch.py +++ b/bitbake/lib/bb/tests/fetch.py | |||
| @@ -308,6 +308,21 @@ class URITest(unittest.TestCase): | |||
| 308 | 'params': {"someparam" : "1"}, | 308 | 'params': {"someparam" : "1"}, |
| 309 | 'query': {}, | 309 | 'query': {}, |
| 310 | 'relative': True | 310 | 'relative': True |
| 311 | }, | ||
| 312 | "https://www.innodisk.com/Download_file?9BE0BF6657;downloadfilename=EGPL-T101.zip": { | ||
| 313 | 'uri': 'https://www.innodisk.com/Download_file?9BE0BF6657;downloadfilename=EGPL-T101.zip', | ||
| 314 | 'scheme': 'https', | ||
| 315 | 'hostname': 'www.innodisk.com', | ||
| 316 | 'port': None, | ||
| 317 | 'hostport': 'www.innodisk.com', | ||
| 318 | 'path': '/Download_file', | ||
| 319 | 'userinfo': '', | ||
| 320 | 'userinfo': '', | ||
| 321 | 'username': '', | ||
| 322 | 'password': '', | ||
| 323 | 'params': {"downloadfilename" : "EGPL-T101.zip"}, | ||
| 324 | 'query': {"9BE0BF6657": None}, | ||
| 325 | 'relative': False | ||
| 311 | } | 326 | } |
| 312 | 327 | ||
| 313 | } | 328 | } |
