File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed
main/java/io/jenkins/plugins/gitlabbranchsource/helpers
test/java/io/jenkins/plugins/gitlabbranchsource/helpers Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -73,18 +73,29 @@ public static String getServerUrlFromName(String serverName) {
73
73
74
74
@ NonNull
75
75
public static String getServerUrl (GitLabServer server ) {
76
- return server != null ? server .getServerUrl () : GitLabServer .GITLAB_SERVER_URL ;
76
+ if (server == null ) {
77
+ return GitLabServer .GITLAB_SERVER_URL ;
78
+ }
79
+ String url = server .getServerUrl ();
80
+ return sanitizeUrlValue (url );
77
81
}
78
82
79
83
@ NonNull
80
84
private static String getServerUrl (String server ) {
81
85
if (server .startsWith ("http://" ) || server .startsWith ("https://" )) {
82
- return server ;
86
+ return sanitizeUrlValue ( server ) ;
83
87
} else {
84
88
return getServerUrlFromName (server );
85
89
}
86
90
}
87
91
92
+ private static String sanitizeUrlValue (String url ) {
93
+ if (url .endsWith ("/" )) {
94
+ return url .substring (0 , url .length () - 1 );
95
+ }
96
+ return url ;
97
+ }
98
+
88
99
public static UriTemplateBuilder getUriTemplateFromServer (String server ) {
89
100
return UriTemplate .buildFromTemplate (getServerUrl (server ));
90
101
}
Original file line number Diff line number Diff line change
1
+ package io .jenkins .plugins .gitlabbranchsource .helpers ;
2
+
3
+ import static org .hamcrest .MatcherAssert .assertThat ;
4
+ import static org .hamcrest .Matchers .is ;
5
+
6
+ import io .jenkins .plugins .gitlabserverconfig .servers .GitLabServer ;
7
+ import org .junit .Test ;
8
+
9
+ public class GitLabHelperTest {
10
+
11
+ @ Test
12
+ public void server_url_does_not_have_trailing_slash () {
13
+ assertThat (GitLabHelper .getServerUrl (null ), is ("https://gitlab.com" ));
14
+
15
+ GitLabServer server1 = new GitLabServer ("https://company.com/gitlab/" , "comp_server" , "1245" );
16
+ assertThat (GitLabHelper .getServerUrl (server1 ), is ("https://company.com/gitlab" ));
17
+
18
+ GitLabServer server2 = new GitLabServer ("https://gitlab.example.org" , "" , "pw-id" );
19
+ assertThat (GitLabHelper .getServerUrl (server2 ), is ("https://gitlab.example.org" ));
20
+ }
21
+ }
You can’t perform that action at this time.
0 commit comments