From 24d786e197b6af1bec649ab32ff4330dbbe34117 Mon Sep 17 00:00:00 2001 From: Andrew Shirley Date: Thu, 8 Jul 2021 17:34:25 +0100 Subject: [PATCH] Encode all components in the url Signed-off-by: Andrew Shirley Signed-off-by: blam --- plugins/jenkins/src/api/JenkinsApi.ts | 28 ++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/plugins/jenkins/src/api/JenkinsApi.ts b/plugins/jenkins/src/api/JenkinsApi.ts index 5b6a07e38c6bf..e1e5c2df440a0 100644 --- a/plugins/jenkins/src/api/JenkinsApi.ts +++ b/plugins/jenkins/src/api/JenkinsApi.ts @@ -126,9 +126,11 @@ export class JenkinsClient implements JenkinsApi { filter: { branch?: string }, ): Promise { const url = new URL( - `${await this.discoveryApi.getBaseUrl('jenkins')}/v1/entity/${ - entity.namespace - }/${entity.kind}/${entity.name}/projects`, + `${await this.discoveryApi.getBaseUrl( + 'jenkins', + )}/v1/entity/${encodeURIComponent(entity.namespace)}/${encodeURIComponent( + entity.kind, + )}/${encodeURIComponent(entity.name)}/projects`, ); if (filter.branch) { @@ -158,11 +160,13 @@ export class JenkinsClient implements JenkinsApi { jobName: string, buildNumber: string, ): Promise { - const url = `${await this.discoveryApi.getBaseUrl('jenkins')}/v1/entity/${ - entity.namespace - }/${entity.kind}/${entity.name}/job/${encodeURIComponent( + const url = `${await this.discoveryApi.getBaseUrl( + 'jenkins', + )}/v1/entity/${encodeURIComponent(entity.namespace)}/${encodeURIComponent( + entity.kind, + )}/${encodeURIComponent(entity.name)}/job/${encodeURIComponent( jobName, - )}/${buildNumber}`; + )}/${encodeURIComponent(buildNumber)}`; const idToken = await this.identityApi.getIdToken(); const response = await fetch(url, { @@ -180,11 +184,13 @@ export class JenkinsClient implements JenkinsApi { jobName: string, buildNumber: string, ): Promise { - const url = `${await this.discoveryApi.getBaseUrl('jenkins')}/v1/entity/${ - entity.namespace - }/${entity.kind}/${entity.name}/job/${encodeURIComponent( + const url = `${await this.discoveryApi.getBaseUrl( + 'jenkins', + )}/v1/entity/${encodeURIComponent(entity.namespace)}/${encodeURIComponent( + entity.kind, + )}/${encodeURIComponent(entity.name)}/job/${encodeURIComponent( jobName, - )}/${buildNumber}:rebuild`; + )}/${encodeURIComponent(buildNumber)}:rebuild`; const idToken = await this.identityApi.getIdToken(); await fetch(url, {