Skip to content
Prev Previous commit
Next Next commit
fix globToRegex
  • Loading branch information
Skn0tt committed Apr 24, 2025
commit bb34b26ef53ee0d64a5d2ff6299c2f3a08424950
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ String tracingStarted(String tracesDir, String traceName) {
return json.get("stacksId").getAsString();
}

Pattern globToRegex(String glob, String baseUrl, String websocketUrl) {
Pattern globToRegex(String glob, String baseURL, boolean webSocketUrl) {
JsonObject params = new JsonObject();
params.addProperty("glob", glob);
if (baseUrl != null) {
params.addProperty("baseUrl", baseUrl);
}
if (websocketUrl != null) {
params.addProperty("websocketUrl", websocketUrl);
if (baseURL != null) {
params.addProperty("baseURL", baseURL);
}
params.addProperty("webSocketUrl", webSocketUrl);
JsonObject json = connection.localUtils().sendMessage("globToRegex", params).getAsJsonObject();
return Pattern.compile(json.get("regex").getAsString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,22 @@ private UrlMatcher(LocalUtils localUtils, URL baseURL, String glob, Pattern patt
}

boolean test(String value) {
return testImpl(localUtils, baseURL, pattern, predicate, glob, value);
return testImpl(localUtils, baseURL, pattern, predicate, glob, value, false);
}

private static boolean testImpl(LocalUtils localUtils, String baseURL, Pattern pattern, Predicate<String> predicate, String glob, String value) {
boolean testWebsocket(String value) {
return testImpl(localUtils, baseURL, pattern, predicate, glob, value, true);
}

private static boolean testImpl(LocalUtils localUtils, String baseURL, Pattern pattern, Predicate<String> predicate, String glob, String value, boolean isWebSocket) {
if (pattern != null) {
return pattern.matcher(value).find();
}
if (predicate != null) {
return predicate.test(value);
}
if (glob != null) {
return localUtils.globToRegex(glob, baseURL, null).matcher(value).find();
return localUtils.globToRegex(glob, baseURL, isWebSocket).matcher(value).find();
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void add(UrlMatcher matcher, Consumer<WebSocketRoute> handler) {

boolean handle(WebSocketRouteImpl route) {
for (RouteInfo routeInfo: routes) {
if (routeInfo.matcher.test(route.url())) {
if (routeInfo.matcher.testWebsocket(route.url())) {
routeInfo.handle(route);
return true;
}
Expand Down
Loading