Skip to content

Commit 311f94e

Browse files
committed
fix: throw error if route segment is empty or null
1 parent 74dc904 commit 311f94e

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/main/java/com/meilisearch/sdk/http/URLBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public URLBuilder(String rootRoute) {
2121
}
2222

2323
public URLBuilder addSubroute(String route) {
24+
if (route == null || route.isEmpty()) {
25+
throw new IllegalArgumentException("route segment must not be null or empty");
26+
}
2427
routes.append("/");
2528
routes.append(route);
2629
return this;

src/test/java/com/meilisearch/sdk/http/URLBuilderTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.hamcrest.Matchers.is;
66
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
77
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertThrows;
89

910
import java.text.SimpleDateFormat;
1011
import java.util.Date;
@@ -32,6 +33,14 @@ void addSubrouteWithMultipleRoutes() {
3233
assertThat(classToTest.getRoutes().toString(), is(equalTo("/route1/route2/route3/route4")));
3334
}
3435

36+
@Test
37+
void addSubrouteWithNullOrEmptyRoute() {
38+
assertThat(
39+
assertThrows(IllegalArgumentException.class, () -> classToTest.addSubroute(""))
40+
.getMessage(),
41+
is(equalTo("route segment must not be null or empty")));
42+
}
43+
3544
@Test
3645
void addParameterStringInt() {
3746
classToTest.addParameter("parameter1", 1);

0 commit comments

Comments
 (0)