diff options
author | Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com> | 2025-03-07 10:43:20 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-03-07 15:38:15 +0000 |
commit | bae86fe618075f28b708d2c89d247937a75226fc (patch) | |
tree | 41d9b3e271e3a93e0f6614cdbae6a29037a59263 | |
parent | 5323603048ddf713b883f945ec90ce04b8a841eb (diff) | |
download | poky-bae86fe618075f28b708d2c89d247937a75226fc.tar.gz |
bitbake: fetch2: Partial revert decodeurl() to not use the URI class
This partial reverts commit a5d569c94700f04b8193c6bccae5af619931b00f
which changes decodeurl() to use the URI class to parse the URL instead
of doing it itself. While reusing code is generally a good idea, using
urllib.parse.urlparse() (which the URI class does) to parse the regular
expression "URLs" that are used in PREMIRRORS and MIRRORS does not work.
A regular expression URL containing https?://... would be silently
ignored, while a URL using a negative lookahead such as
git://(?!internal\.git\.server).*/.* would result in a cryptic error:
Exception: re.error: missing ), unterminated subpattern at position 0
The problem is that urllib.parse.urlparse() treats the ? as the start of
URL parameters and thus stops parsing whatever part of the URL it was
parsing. Restore the old function and use it in the PREMIRRORS and
MIRRORS code.
(Bitbake rev: f8a7712754e6d0199a0d227fca288307b935368d)
Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/lib/bb/fetch2/__init__.py | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py index 93fe012ec3..5aa67accc3 100644 --- a/bitbake/lib/bb/fetch2/__init__.py +++ b/bitbake/lib/bb/fetch2/__init__.py | |||
@@ -357,6 +357,54 @@ def decodeurl(url): | |||
357 | path = uri.path if uri.path else "/" | 357 | path = uri.path if uri.path else "/" |
358 | return uri.scheme, uri.hostport, path, uri.username, uri.password, uri.params | 358 | return uri.scheme, uri.hostport, path, uri.username, uri.password, uri.params |
359 | 359 | ||
360 | def decodemirrorurl(url): | ||
361 | """Decodes a mirror URL into the tokens (scheme, network location, path, | ||
362 | user, password, parameters). | ||
363 | """ | ||
364 | m = re.compile('(?P<type>[^:]*)://((?P<user>[^/;]+)@)?(?P<location>[^;]+)(;(?P<parm>.*))?').match(url) | ||
365 | if not m: | ||
366 | raise MalformedUrl(url) | ||
367 | |||
368 | type = m.group('type') | ||
369 | location = m.group('location') | ||
370 | if not location: | ||
371 | raise MalformedUrl(url) | ||
372 | user = m.group('user') | ||
373 | parm = m.group('parm') | ||
374 | |||
375 | locidx = location.find('/') | ||
376 | if locidx != -1 and type.lower() != 'file': | ||
377 | host = location[:locidx] | ||
378 | path = location[locidx:] | ||
379 | elif type.lower() == 'file': | ||
380 | host = "" | ||
381 | path = location | ||
382 | if user: | ||
383 | path = user + '@' + path | ||
384 | user = "" | ||
385 | else: | ||
386 | host = location | ||
387 | path = "/" | ||
388 | if user: | ||
389 | m = re.compile('(?P<user>[^:]+)(:?(?P<pswd>.*))').match(user) | ||
390 | if m: | ||
391 | user = m.group('user') | ||
392 | pswd = m.group('pswd') | ||
393 | else: | ||
394 | user = '' | ||
395 | pswd = '' | ||
396 | |||
397 | p = collections.OrderedDict() | ||
398 | if parm: | ||
399 | for s in parm.split(';'): | ||
400 | if s: | ||
401 | if not '=' in s: | ||
402 | raise MalformedUrl(url, "The URL: '%s' is invalid: parameter %s does not specify a value (missing '=')" % (url, s)) | ||
403 | s1, s2 = s.split('=', 1) | ||
404 | p[s1] = s2 | ||
405 | |||
406 | return type, host, urllib.parse.unquote(path), user, pswd, p | ||
407 | |||
360 | def encodeurl(decoded): | 408 | def encodeurl(decoded): |
361 | """Encodes a URL from tokens (scheme, network location, path, | 409 | """Encodes a URL from tokens (scheme, network location, path, |
362 | user, password, parameters). | 410 | user, password, parameters). |
@@ -391,9 +439,9 @@ def uri_replace(ud, uri_find, uri_replace, replacements, d, mirrortarball=None): | |||
391 | if not ud.url or not uri_find or not uri_replace: | 439 | if not ud.url or not uri_find or not uri_replace: |
392 | logger.error("uri_replace: passed an undefined value, not replacing") | 440 | logger.error("uri_replace: passed an undefined value, not replacing") |
393 | return None | 441 | return None |
394 | uri_decoded = list(decodeurl(ud.url)) | 442 | uri_decoded = list(decodemirrorurl(ud.url)) |
395 | uri_find_decoded = list(decodeurl(uri_find)) | 443 | uri_find_decoded = list(decodemirrorurl(uri_find)) |
396 | uri_replace_decoded = list(decodeurl(uri_replace)) | 444 | uri_replace_decoded = list(decodemirrorurl(uri_replace)) |
397 | logger.debug2("For url %s comparing %s to %s" % (uri_decoded, uri_find_decoded, uri_replace_decoded)) | 445 | logger.debug2("For url %s comparing %s to %s" % (uri_decoded, uri_find_decoded, uri_replace_decoded)) |
398 | result_decoded = ['', '', '', '', '', {}] | 446 | result_decoded = ['', '', '', '', '', {}] |
399 | # 0 - type, 1 - host, 2 - path, 3 - user, 4- pswd, 5 - params | 447 | # 0 - type, 1 - host, 2 - path, 3 - user, 4- pswd, 5 - params |