Skip to content

Commit 7bc2254

Browse files
committed
fix: remove last slash of url
1 parent 08088d6 commit 7bc2254

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
@@ -117,6 +117,9 @@ static String getUrl(String url) {
117117
if (!url.contains("://")) {
118118
url = "http://" + url;
119119
}
120+
if (url.endsWith("/")) {
121+
url = url.substring(0, url.length() - 1);
122+
}
120123
try {
121124
new URL(url);
122125
}

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
@@ -128,7 +128,7 @@ void forType_allFieldsSetOnBuilder() {
128128
assertFactoryBeanField(builder, "contextId", "TestContext");
129129

130130
// and:
131-
assertFactoryBeanField(builder, "url", "http://Url/");
131+
assertFactoryBeanField(builder, "url", "http://Url");
132132
assertFactoryBeanField(builder, "path", "/Path");
133133
assertFactoryBeanField(builder, "dismiss404", true);
134134

@@ -148,7 +148,7 @@ void forType_clientFactoryBeanProvided() {
148148
assertFactoryBeanField(builder, "contextId", "TestContext");
149149

150150
// and:
151-
assertFactoryBeanField(builder, "url", "http://Url/");
151+
assertFactoryBeanField(builder, "url", "http://Url");
152152
assertFactoryBeanField(builder, "path", "/Path");
153153
assertFactoryBeanField(builder, "dismiss404", true);
154154
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)