Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH] get_mirror_url: urlquote only for ftp, http, and https (bug 741474)
Date: Sat, 12 Sep 2020 22:12:13
Message-Id: 20200912220958.23155-1-zmedico@gentoo.org
1 It's necessary to use urlquote for correct behavior with ftp, http,
2 and https, since it's possible for file names to contain percent
3 encoded characters that need to be protected by an additional layer
4 of percent encoding. For other protocols such as sftp and rsync,
5 all characters are interpreted literally, so urlquote must not be
6 used.
7
8 Fixes: c238d5f7ed264179c263f5a2da983c4ee50b4f00
9 Bug: https://bugs.gentoo.org/719810
10 Bug: https://bugs.gentoo.org/741474
11 Signed-off-by: Zac Medico <zmedico@g.o>
12 ---
13 lib/portage/package/ebuild/fetch.py | 8 ++++++--
14 1 file changed, 6 insertions(+), 2 deletions(-)
15
16 diff --git a/lib/portage/package/ebuild/fetch.py b/lib/portage/package/ebuild/fetch.py
17 index 7c61fe463..ca031f31e 100644
18 --- a/lib/portage/package/ebuild/fetch.py
19 +++ b/lib/portage/package/ebuild/fetch.py
20 @@ -513,8 +513,12 @@ def get_mirror_url(mirror_url, filename, mysettings, cache_path=None):
21 json.dump(cache, f)
22 f.close()
23
24 - return (mirror_url + "/distfiles/" +
25 - urlquote(mirror_conf.get_best_supported_layout().get_path(filename)))
26 + # For some protocols, urlquote is required for correct behavior,
27 + # and it must not be used for other protocols like rsync and sftp.
28 + path = mirror_conf.get_best_supported_layout().get_path(filename)
29 + if urlparse(mirror_url).scheme in ('ftp', 'http', 'https'):
30 + path = urlquote(path)
31 + return mirror_url + "/distfiles/" + path
32
33
34 def fetch(myuris, mysettings, listonly=0, fetchonly=0,
35 --
36 2.25.3