bitbake-devel.lists.openembedded.org archive mirror
 help / color / mirror / Atom feed
From: CESTONARO Thilo <thilo.cestonaro@thalesgroup.com>
To: Richard Purdie <richard.purdie@linuxfoundation.org>,
	"bitbake-devel@lists.openembedded.org"
	<bitbake-devel@lists.openembedded.org>
Subject: [PATCH v2] bitbake: git fetcher: use urllib quote ...
Date: Wed, 10 May 2023 13:10:51 +0000	[thread overview]
Message-ID: <PR0P264MB1882562678B304BEBDDFC68AE9779@PR0P264MB1882.FRAP264.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <b4f209d135c1dcf47253ba561ccbde128b0123e9.camel@linuxfoundation.org>

[-- Attachment #1: Type: text/plain, Size: 419 bytes --]

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




[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-bitbake-git-fetcher-use-urllib-quote.patch --]
[-- Type: text/x-patch; name="0001-bitbake-git-fetcher-use-urllib-quote.patch", Size: 2286 bytes --]

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


  reply	other threads:[~2023-05-10 13:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-22  8:37 [PATCH] bitbake: git fetcher: use urllib quote CESTONARO Thilo
2023-03-22 10:40 ` [bitbake-devel] " Michael Opdenacker
2023-04-19 12:22   ` AW: " CESTONARO Thilo
2023-03-24 10:13 ` Alexandre Belloni
2023-04-20 11:43 ` Richard Purdie
2023-05-10 13:10   ` CESTONARO Thilo [this message]
2023-05-10 13:24     ` [bitbake-devel] [PATCH v2] " Michael Opdenacker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=PR0P264MB1882562678B304BEBDDFC68AE9779@PR0P264MB1882.FRAP264.PROD.OUTLOOK.COM \
    --to=thilo.cestonaro@thalesgroup.com \
    --cc=bitbake-devel@lists.openembedded.org \
    --cc=richard.purdie@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).