From cfd980d59dc6f293e0e9895cf09e46ed708972c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Wilko=C5=82azki?= Date: Thu, 7 Sep 2023 16:59:41 +0200 Subject: [PATCH 1/2] Fix double encoding of $job_name Removed call to self::encodePath, as the `job` parameter is part of a url query, which is later encoded by `QueryStringBuilder` in `AbstractApi::prepareUri` --- src/Api/Jobs.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Api/Jobs.php b/src/Api/Jobs.php index 70d7a28f..bd318f89 100644 --- a/src/Api/Jobs.php +++ b/src/Api/Jobs.php @@ -151,7 +151,7 @@ public function artifacts($project_id, int $job_id) public function artifactsByRefName($project_id, string $ref_name, string $job_name) { return $this->getAsResponse('projects/'.self::encodePath($project_id).'/jobs/artifacts/'.self::encodePath($ref_name).'/download', [ - 'job' => self::encodePath($job_name), + 'job' => $job_name, ])->getBody(); } @@ -166,7 +166,7 @@ public function artifactsByRefName($project_id, string $ref_name, string $job_na public function artifactByRefName($project_id, string $ref_name, string $job_name, string $artifact_path) { return $this->getAsResponse('projects/'.self::encodePath($project_id).'/jobs/artifacts/'.self::encodePath($ref_name).'/raw/'.self::encodePath($artifact_path), [ - 'job' => self::encodePath($job_name), + 'job' => $job_name, ])->getBody(); } From 5f3060e83a92b09c84d0374e1ecfc47bb9030115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Wilko=C5=82azki?= Date: Thu, 7 Sep 2023 17:17:08 +0200 Subject: [PATCH 2/2] Use `job name` with space to test url encoding --- tests/Api/JobsTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Api/JobsTest.php b/tests/Api/JobsTest.php index 307acf1f..9ca55526 100644 --- a/tests/Api/JobsTest.php +++ b/tests/Api/JobsTest.php @@ -171,12 +171,12 @@ public function shouldGetArtifactsByRefName(): void $api->expects($this->once()) ->method('getAsResponse') ->with('projects/1/jobs/artifacts/master/download', [ - 'job' => 'job_name', + 'job' => 'job name', ]) ->will($this->returnValue($returnedStream)) ; - $this->assertEquals('foobar', $api->artifactsByRefName(1, 'master', 'job_name')->getContents()); + $this->assertEquals('foobar', $api->artifactsByRefName(1, 'master', 'job name')->getContents()); } /** @@ -189,11 +189,11 @@ public function shouldGetArtifactByRefName(): void $api->expects($this->once()) ->method('getAsResponse') ->with('projects/1/jobs/artifacts/master/raw/artifact_path', [ - 'job' => 'job_name', + 'job' => 'job name', ]) ->will($this->returnValue($returnedStream)) ; - $this->assertEquals('foobar', $api->artifactByRefName(1, 'master', 'job_name', 'artifact_path')->getContents()); + $this->assertEquals('foobar', $api->artifactByRefName(1, 'master', 'job name', 'artifact_path')->getContents()); } /**