Skip to content

Commit

Permalink
Fix for: Exception occurring when encoding the path containing space
Browse files Browse the repository at this point in the history
Fixes #358
  • Loading branch information
lwitkowski committed Mar 28, 2024
1 parent e8c2d4c commit e002719
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ void jaxRsNotFoundShouldReturn404ProblemInsteadOfDefaultRestEasyDefaultResponse(
.body("stacktrace", nullValue());
}

@Test
void jaxRsNotFoundShouldHandleSpacesInUriProperly() {
given()
.queryParam("message", SAMPLE_DETAIL)
.get("/throw/jax-rs/not-found exception")
.then()
.statusCode(NOT_FOUND.getStatusCode())
.body("title", equalTo(NOT_FOUND.getReasonPhrase()))
.body("status", equalTo(NOT_FOUND.getStatusCode()))
.body("instance", equalTo("/throw/jax-rs/not-found%20exception"));
}

@Test
void jaxRsForbiddenShouldReturn403ProblemInsteadOfDefaultRestEasyDefaultResponse() {
given()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.tietoevry.quarkus.resteasy.problem.HttpProblem;
import java.net.URI;
import java.net.URISyntaxException;

/**
* Replaces <code>null</code> value of <code>instance</code> with URI of currently served endpoint, i.e
Expand All @@ -26,7 +27,14 @@ public HttpProblem apply(HttpProblem problem, ProblemContext context) {
}

private URI defaultInstance(ProblemContext context) {
return context.path == null ? null : URI.create(context.path);
if (context.path == null) {
return null;
}
try {
return new URI(context.path.replaceAll(" ", "%20"));
} catch (URISyntaxException e) {
return null;
}
}

}

0 comments on commit e002719

Please sign in to comment.