Skip to content

Commit

Permalink
Validate path
Browse files Browse the repository at this point in the history
  • Loading branch information
malkusch committed Nov 6, 2023
1 parent 8891aad commit 02cdb4e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main/java/de/malkusch/km200/KM200.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ public void update(String path, BigDecimal value) throws KM200Exception, IOExcep
}

private void update(String path, Object update) throws KM200Exception, IOException, InterruptedException {
assertPath(path);

String json = null;
try {
json = mapper.writeValueAsString(update);
Expand All @@ -186,10 +188,7 @@ private void update(String path, Object update) throws KM200Exception, IOExcepti
}

public String query(String path) throws KM200Exception, IOException, InterruptedException {
assertNotBlank(path, "Path must not be blank");
if (!path.startsWith("/")) {
throw new IllegalArgumentException("Path must start with a leading /");
}
assertPath(path);

var response = queryHttp.get(path);
var encrypted = response.body();
Expand Down Expand Up @@ -235,6 +234,13 @@ private JsonNode queryJson(String path) throws KM200Exception, IOException, Inte
}
}

private static void assertPath(String path) {
assertNotBlank(path, "Path must not be blank");
if (!path.startsWith("/")) {
throw new IllegalArgumentException("Path must start with a leading /");
}
}

private static void assertNotBlank(String var, String message) {
if (requireNonNull(var).isBlank()) {
throw new IllegalArgumentException(message);
Expand Down

0 comments on commit 02cdb4e

Please sign in to comment.