Skip to content

Commit e84909a

Browse files
committed
Handle nullable http-request path correctly
1 parent 593af99 commit e84909a

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

common/src/main/java/de/bluecolored/bluemap/common/web/FileRequestHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public HttpResponse handle(HttpRequest request) {
6565

6666
private HttpResponse generateResponse(HttpRequest request) throws IOException {
6767
String path = request.getPath();
68+
if (path == null) return new HttpResponse(HttpStatusCode.BAD_REQUEST);
6869

6970
// normalize path
7071
if (path.startsWith("/")) path = path.substring(1);

common/src/main/java/de/bluecolored/bluemap/common/web/RoutingRequestHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public void register(Pattern pattern, String replacementRoute, HttpRequestHandle
6767
@Override
6868
public HttpResponse handle(HttpRequest request) {
6969
String path = request.getPath();
70+
if (path == null) return new HttpResponse(HttpStatusCode.BAD_REQUEST);
7071

7172
// normalize path
7273
if (path.startsWith("/")) path = path.substring(1);

common/src/main/java/de/bluecolored/bluemap/common/web/http/HttpRequest.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
package de.bluecolored.bluemap.common.web.http;
2626

27+
import org.jetbrains.annotations.Nullable;
28+
2729
import java.io.ByteArrayInputStream;
2830
import java.io.IOException;
2931
import java.io.InputStream;
@@ -218,7 +220,7 @@ public InputStream getDataStream() {
218220
return new ByteArrayInputStream(data);
219221
}
220222

221-
public String getPath() {
223+
public @Nullable String getPath() {
222224
if (path == null) parseAddress();
223225
return path;
224226
}
@@ -232,7 +234,7 @@ public Map<String, String> getGETParams() {
232234
return getParams;
233235
}
234236

235-
public String getGETParamString() {
237+
public @Nullable String getGETParamString() {
236238
if (getParamString == null) parseAddress();
237239
return getParamString;
238240
}
@@ -249,12 +251,15 @@ private void parseAddress() {
249251

250252
private void parseGetParams() {
251253
Map<String, String> getParams = new HashMap<>();
252-
for (String getParam : this.getGETParamString().split("&")){
253-
if (getParam.isEmpty()) continue;
254-
String[] kv = getParam.split("=", 2);
255-
String key = kv[0];
256-
String value = kv.length > 1 ? kv[1] : "";
257-
getParams.put(key, value);
254+
String getParamString = this.getGETParamString();
255+
if (getParamString != null) {
256+
for (String getParam : getParamString.split("&")) {
257+
if (getParam.isEmpty()) continue;
258+
String[] kv = getParam.split("=", 2);
259+
String key = kv[0];
260+
String value = kv.length > 1 ? kv[1] : "";
261+
getParams.put(key, value);
262+
}
258263
}
259264
this.getParams = getParams;
260265
}

0 commit comments

Comments
 (0)