Skip to content

Optimise path decoding in RoutingUtils #47395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.quarkus.vertx.http.runtime;

import java.net.URI;
import java.util.Set;

import io.vertx.core.http.HttpHeaders;
import io.vertx.core.http.impl.MimeMapping;
import io.vertx.core.net.impl.URIDecoder;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.handler.StaticHandler;

Expand All @@ -17,18 +17,21 @@ private RoutingUtils() throws IllegalAccessException {
/**
* Get the normalized and decoded path:
* - normalize based on RFC3986
* - convert % encoded characters to their non encoded form (using {@link java.net.URI})
* - convert % encoded characters to their non encoded form (using {@link URIDecoder#decodeURIComponent})
* - invalid if the path contains '?' (query section of the path)
*
* @param ctx the RoutingContext
* @return the normalized and decoded path or null if not valid
*/
public static String getNormalizedAndDecodedPath(RoutingContext ctx) {
String normalizedPath = ctx.normalizedPath();
if (normalizedPath.contains("?")) {
if (normalizedPath.indexOf('?') != -1) {
return null;
}
return URI.create(normalizedPath).getPath();
if (normalizedPath.indexOf('%') == -1) {
return normalizedPath;
}
return URIDecoder.decodeURIComponent(normalizedPath);
}

/**
Expand Down
Loading