Skip to content

Commit 4b52821

Browse files
committed
feat: filter out invalid (null/blank) query parameters
1 parent 68978c8 commit 4b52821

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/main/java/io/weaviate/client6/v1/internal/rest/UrlEncoder.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.Map;
77
import java.util.stream.Collectors;
88

9-
public final class UrlEncoder {
9+
final class UrlEncoder {
1010

1111
private static String encodeValue(Object value) {
1212
try {
@@ -16,11 +16,28 @@ private static String encodeValue(Object value) {
1616
}
1717
}
1818

19+
/**
20+
* Encodes each key-value pair into a URL-compatible query string, omitting any
21+
* {@code null} or blank (in case of String parameter) values.
22+
* Each value is represented by the return of its [@conde toString()} method.
23+
*
24+
* @return URL query string or empty string if the map was empty
25+
* or contained no valid parameters.
26+
*/
1927
public static String encodeQuery(Map<String, Object> queryParams) {
2028
if (queryParams == null || queryParams.isEmpty()) {
2129
return "";
2230
}
2331
return queryParams.entrySet().stream()
32+
.filter(qp -> {
33+
if (qp == null) {
34+
return false;
35+
}
36+
if (qp.getValue() instanceof String str) {
37+
return !str.isBlank();
38+
}
39+
return true;
40+
})
2441
.map(qp -> qp.getKey() + "=" + encodeValue(qp.getValue()))
2542
.collect(Collectors.joining("&", "?", ""));
2643
}

0 commit comments

Comments
 (0)