diff --git a/src/main/java/com/intuit/karate/core/MockHandler.java b/src/main/java/com/intuit/karate/core/MockHandler.java index 2851d1a..e4fe444 100644 --- a/src/main/java/com/intuit/karate/core/MockHandler.java +++ b/src/main/java/com/intuit/karate/core/MockHandler.java @@ -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 diff --git a/src/main/java/io/github/apimock/OpenApiValidator4Karate.java b/src/main/java/io/github/apimock/OpenApiValidator4Karate.java index 9dbef72..fc8ca4f 100644 --- a/src/main/java/io/github/apimock/OpenApiValidator4Karate.java +++ b/src/main/java/io/github/apimock/OpenApiValidator4Karate.java @@ -116,7 +116,7 @@ public void reload() { public static Operation findOperation(String method, String requestPath, OpenApi3 api) { List> 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() : @@ -221,7 +221,7 @@ protected Map 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;