Skip to content

Commit

Permalink
Allow config editor to unset a property
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Feb 9, 2021
1 parent 1c234ad commit e95d5cb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,22 @@ protected void handlePost(RoutingContext event, MultiMap form) throws Exception
int nameLine = -1;
for (int i = 0, linesSize = lines.size(); i < linesSize; i++) {
final String line = lines.get(i);
if (line.startsWith(name)) {
if (line.startsWith(name + "=")) {
nameLine = i;
break;
}
}

if (nameLine != -1) {
lines.set(nameLine, name + "=" + value);
if (value.isEmpty()) {
lines.remove(nameLine);
} else {
lines.set(nameLine, name + "=" + value);
}
} else {
lines.add(name + "=" + value);
if (!value.isEmpty()) {
lines.add(name + "=" + value);
}
}

try (BufferedWriter writer = Files.newBufferedWriter(configPath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,20 @@ public void testChangeHttpRoute() {

}

@Test
public void testSetEmptyValue() {
RestAssured.with()
.get("q/arc/beans")
.then()
.statusCode(200);
RestAssured.with().formParam("name", "quarkus.http.root-path").formParam("value", "")
.redirects().follow(false)
.post("q/dev/io.quarkus.quarkus-vertx-http/config")
.then()
.statusCode(303);
RestAssured.with()
.get("q/arc/beans")
.then()
.statusCode(200);
}
}

0 comments on commit e95d5cb

Please sign in to comment.