From c5ba0e911cd7edb44bb44dfa34a43946bd5f682e Mon Sep 17 00:00:00 2001 From: Frank Lichtenheld Date: Mon, 17 Mar 2025 14:12:38 +0100 Subject: [PATCH 1/2] Replace requests.utils.quote with urllib.parse.quote quote is not officially part of requests.utils API, it is just imported from requests.compat which imports it from urllib.parse. So just use it directly. Much less confusing. Signed-off-by: Frank Lichtenheld --- artifactory.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/artifactory.py b/artifactory.py index 0c4b63c..f95b741 100755 --- a/artifactory.py +++ b/artifactory.py @@ -413,14 +413,14 @@ def quote_url(url): logger.debug(f"Raw URL passed for encoding: {url}") parsed_url = urllib3.util.parse_url(url) if parsed_url.port: - quoted_path = requests.utils.quote( + quoted_path = urllib.parse.quote( url.partition(f"{parsed_url.host}:{parsed_url.port}")[2] ) quoted_url = ( f"{parsed_url.scheme}://{parsed_url.host}:{parsed_url.port}{quoted_path}" ) else: - quoted_path = requests.utils.quote(url.partition(parsed_url.host)[2]) + quoted_path = urllib.parse.quote(url.partition(parsed_url.host)[2]) quoted_url = f"{parsed_url.scheme}://{parsed_url.host}{quoted_path}" return quoted_url @@ -2839,7 +2839,7 @@ def _get_info(self, build_name, build_number=""): # If a build name contains slash "/" it must be encoded, # otherwise the part after the slash will be treated as a build number # maven-demo/1-build-snapshot => maven-demo%2F1-build-snapshot - url = requests.utils.quote(build_name, safe="") + url = urllib.parse.quote(build_name, safe="") if build_number: url += f"/{build_number}" return self._get_build_api_response(url) From 0f01db171f97d31374470687152b54024285ca9a Mon Sep 17 00:00:00 2001 From: Frank Lichtenheld Date: Mon, 17 Mar 2025 14:14:39 +0100 Subject: [PATCH 2/2] BuildManager: unquote build names Since we quote the build names when using them in a URL we need to make sure they are unquoted to begin with to avoid double quoting. Happens e.g. with builds containing spaces. Signed-off-by: Frank Lichtenheld --- artifactory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/artifactory.py b/artifactory.py index f95b741..40eea4d 100755 --- a/artifactory.py +++ b/artifactory.py @@ -2796,7 +2796,7 @@ def builds(self): if "builds" in resp: for build in resp["builds"]: arti_build = ArtifactoryBuild( - name=build["uri"][1:], + name=urllib.parse.unquote(build["uri"][1:]), last_started=build["lastStarted"], build_manager=self, )