From 1bc898b5e1abd98d2932dce053dc82b3f3d6b3f8 Mon Sep 17 00:00:00 2001
From: Thilo Cestonaro <thilo.cestonaro@thalesgroup.com>
Date: Tue, 7 Feb 2023 13:44:02 +0100
Subject: [PATCH] bitbake: git fetcher: use urllib quote ...
to use the path url-compatible. This needs to happen before the shell quotation happens.
Without this commit, spaces in the clone URL will be used as " " and not as "%20" which will fail.
This commit changes the " " in the URL to "%20" when it is a http or https url.
Signed-off-by: Thilo Cestonaro <thilo.cestonaro@thalesgroup.com>
---
lib/bb/fetch2/git.py | 8 +++++++-
lib/bb/tests/fetch.py | 13 +++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
@@ -67,6 +67,7 @@ import re
import shlex
import subprocess
import tempfile
+import urllib
import bb
import bb.progress
from contextlib import contextmanager
@@ -698,7 +699,12 @@ class Git(FetchMethod):
username = ud.user + '@'
else:
username = ""
- return "%s://%s%s%s" % (ud.proto, username, ud.host, ud.path)
+
+ path = ud.path
+ if ud.proto in [ 'http', 'https' ]:
+ path = urllib.parse.quote(ud.path)
+
+ return "%s://%s%s%s" % (ud.proto, username, ud.host, path)
def _revision_key(self, ud, d, name):
"""
@@ -1697,6 +1697,19 @@ class GitShallowTest(FetcherTest):
ud = fetcher.ud[uri]
return fetcher, ud
+ def assert_uri_with_spaces(self):
+ class FetchDataFake():
+ proto = "https"
+ user = ""
+ host = "example.org"
+ path = "/git/url with spaces/imaginary.git"
+
+ m = bb.fetch2.git.Git(self.d)
+ ud = FetchDataFake()
+ urlgenerated = m._get_repo_url(ud)
+
+ self.assertEqual("https://example.org/git/url%20with%20spaces/imaginary.git", urlgenerated)
+
def fetch_and_unpack(self, uri=None):
fetcher, ud = self.fetch(uri)
fetcher.unpack(self.d.getVar('WORKDIR'))
--
2.39.2