diff mbox series

[v2] bitbake: git fetcher: use urllib quote ...

Message ID PR0P264MB1882562678B304BEBDDFC68AE9779@PR0P264MB1882.FRAP264.PROD.OUTLOOK.COM
State New
Headers show
Series [v2] bitbake: git fetcher: use urllib quote ... | expand

Commit Message

CESTONARO Thilo May 10, 2023, 1:10 p.m. UTC
Hi Richard!

> I'd like to ensure that we add test coverage to "bitbake-selftest" to
> cover this situation (see lib/bb/tests/fetch.py).
> 
> We tend not to accept fixes like this unless we have test coverage to
> prevent future regressions.

Next version of my patch. I tried to have a as simple as possible test which exactly does show what goes wrong without my patch.

Thank you!

Cheers,
Thilo

Comments

Michael Opdenacker May 10, 2023, 1:24 p.m. UTC | #1
Hi Thilo,

On 10.05.23 at 15:10, Thilo C. via lists.openembedded.org wrote:
> Hi Richard!
>
>> I'd like to ensure that we add test coverage to "bitbake-selftest" to
>> cover this situation (see lib/bb/tests/fetch.py).
>>
>> We tend not to accept fixes like this unless we have test coverage to
>> prevent future regressions.
> Next version of my patch. I tried to have a as simple as possible test which exactly does show what goes wrong without my patch.


Thank you very much for the patch, but please don't send it as an 
attachment. Otherwise, people cannot comment or ask questions about 
specific lines.

You should basically send your patches through "git send-email". See 
https://www.openembedded.org/wiki/How_to_submit_a_patch_to_OpenEmbedded

Thanks in advance :)
Michael.
diff mbox series

Patch

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(-)

diff --git a/lib/bb/fetch2/git.py b/lib/bb/fetch2/git.py
index 2a3c06fe..28729241 100644
--- a/lib/bb/fetch2/git.py
+++ b/lib/bb/fetch2/git.py
@@ -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):
         """
diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py
index 6ef0836f..db798f0d 100644
--- a/lib/bb/tests/fetch.py
+++ b/lib/bb/tests/fetch.py
@@ -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