Light, fluffy, and always free - The AWS Local Emulator alternative
fix(apigatewayv2): fix route matching for path-parameter routes (#368)
TiM9e79859ceae9
diff --git a/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2Service.java b/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2Service.javaindex 3cb3f76db2..2963b55b69 100644--- a/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2Service.java+++ b/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2Service.java@@ -185,12 +185,19 @@ public class ApiGatewayV2Service {String pattern = routeKey.substring(space + 1);if (!method.equalsIgnoreCase(httpMethod)) return false;- // Convert path template to regex: {param} → [^/]+, {proxy+} → .+- String regex = "^" + Pattern.quote(pattern)- .replace("\\{proxy+\\}", "\\E.+\\Q")- .replace("\\{", "\\E[^/]+\\Q")- .replaceAll("\\\\Q\\\\E", "") + "$";- return path.matches(regex);+ // Build regex from path template: {proxy+} -> .+, {param} -> [^/]++ // Quote literal segments to avoid regex injection from path patterns+ StringBuilder regex = new StringBuilder("^");+ java.util.regex.Matcher m = java.util.regex.Pattern.compile("\\{([^}]*)}").matcher(pattern);+ int last = 0;+ while (m.find()) {+ regex.append(Pattern.quote(pattern.substring(last, m.start())));+ regex.append(m.group(1).endsWith("+") ? ".+" : "[^/]+");+ last = m.end();+ }+ regex.append(Pattern.quote(pattern.substring(last)));+ regex.append("$");+ return path.matches(regex.toString());}// ──────────────────────────── Integration CRUD ────────────────────────────