Skip to content

Commit

Permalink
[fix] Fix compatibility with karate for path and prefix with "/"
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangsa committed Apr 6, 2022
1 parent e1bdd09 commit 19a9863
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/intuit/karate/core/MockHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ public synchronized Response handle(Request req) { // note the [synchronized]
}
return response;
}
if (prefix != null && req.getPath().startsWith(prefix)) {
req.setPath(req.getPath().substring(prefix.length()));
String path = ("/" + req.getPath()).replaceFirst("^//", "/");
if (prefix != null && path.startsWith(prefix)) {
req.setPath(path.substring(prefix.length()));
}
// rare case when http-client is active within same jvm
// snapshot existing thread-local to restore
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/github/apimock/OpenApiValidator4Karate.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void reload() {

public static Operation findOperation(String method, String requestPath, OpenApi3 api) {
List<Map.Entry<String, Path>> paths = api.getPaths().entrySet().stream()
.filter(e -> HttpUtils.parseUriPattern(e.getKey(), requestPath) != null)
.filter(e -> HttpUtils.parseUriPattern(e.getKey(), requestPath) != null ||HttpUtils.parseUriPattern(e.getKey(), "/" + requestPath) != null)
.collect(Collectors.toList());
Path path = paths.size() == 1?
paths.get(0).getValue() :
Expand Down Expand Up @@ -221,7 +221,7 @@ protected Map<String, MediaType> getMediaTypes(final Operation operation, final
private static String fixUrl(String url) {
url = url.startsWith("/")? url : "/" + url;;
try {
return URLEncoder.encode(url, "UTF8");
return URLEncoder.encode(url, "UTF8").replaceAll("%2F", "/");
} catch (UnsupportedEncodingException e) {
logger.error("UnsupportedEncodingException UTF8 encoding request path", e);
return url;
Expand Down

0 comments on commit 19a9863

Please sign in to comment.