Skip to content

Commit f9e55b5

Browse files
birariroOlgaMaciaszek
authored andcommitted
fix: remove last slash of url
1 parent b56dc8d commit f9e55b5

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsRegistrar.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ static String getUrl(String url) {
118118
if (!url.contains("://")) {
119119
url = "http://" + url;
120120
}
121+
if (url.endsWith("/")) {
122+
url = url.substring(0, url.length() - 1);
123+
}
121124
try {
122125
new URL(url);
123126
}

spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientBuilderTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void forType_allFieldsSetOnBuilder() {
131131
assertFactoryBeanField(builder, "contextId", "TestContext");
132132

133133
// and:
134-
assertFactoryBeanField(builder, "url", "http://Url/");
134+
assertFactoryBeanField(builder, "url", "http://Url");
135135
assertFactoryBeanField(builder, "path", "/Path");
136136
assertFactoryBeanField(builder, "dismiss404", true);
137137

@@ -155,7 +155,7 @@ void forType_clientFactoryBeanProvided() {
155155
assertFactoryBeanField(builder, "contextId", "TestContext");
156156

157157
// and:
158-
assertFactoryBeanField(builder, "url", "http://Url/");
158+
assertFactoryBeanField(builder, "url", "http://Url");
159159
assertFactoryBeanField(builder, "path", "/Path");
160160
assertFactoryBeanField(builder, "dismiss404", true);
161161
List<FeignBuilderCustomizer> additionalCustomizers = getFactoryBeanField(builder, "additionalCustomizers");

spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientsRegistrarTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ private String testGetName(String name) {
8989
return registrar.getName(Collections.singletonMap("name", name));
9090
}
9191

92+
@Test
93+
void removeLastSlashOfUrl() {
94+
String url = FeignClientsRegistrar.getUrl("http://localhost/");
95+
assertThat(url).isEqualTo("http://localhost");
96+
}
97+
9298
@Test
9399
void testFallback() {
94100
assertThatExceptionOfType(IllegalArgumentException.class)

0 commit comments

Comments
 (0)