From 3a7c8c60ca1a3cbd87959f795a70203d6556e35b Mon Sep 17 00:00:00 2001 From: Pierre Guillot Date: Fri, 29 Nov 2019 11:13:22 +0100 Subject: [PATCH] SONAR-12760 remove trailing slash in gitlab url setting --- .../src/main/java/org/sonar/auth/gitlab/GitLabSettings.java | 6 +++++- .../test/java/org/sonar/auth/gitlab/GitLabSettingsTest.java | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GitLabSettings.java b/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GitLabSettings.java index 7eb6c23670f..9dbc7a61e91 100644 --- a/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GitLabSettings.java +++ b/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GitLabSettings.java @@ -48,7 +48,11 @@ public class GitLabSettings { } public String url() { - return configuration.get(GITLAB_AUTH_URL).orElse(null); + String url = configuration.get(GITLAB_AUTH_URL).orElse(null); + if (url != null && url.endsWith("/")) { + return url.substring(0, url.length() - 1); + } + return url; } public String applicationId() { diff --git a/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GitLabSettingsTest.java b/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GitLabSettingsTest.java index b73fe1826a2..aeff42d7fdb 100644 --- a/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GitLabSettingsTest.java +++ b/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GitLabSettingsTest.java @@ -51,6 +51,11 @@ public class GitLabSettingsTest { @Test public void test_settings() { assertThat(config.url()).isEqualTo("https://gitlab.com"); + + settings.setProperty(GITLAB_AUTH_URL, "https://gitlab.com/api/"); + assertThat(config.url()).isEqualTo("https://gitlab.com/api"); + + settings.setProperty(GITLAB_AUTH_URL, "https://gitlab.com/api"); assertThat(config.url()).isEqualTo("https://gitlab.com/api"); -- 2.39.5