1
1
package io .quarkus .vertx .http .runtime ;
2
2
3
- import java .net .URI ;
4
3
import java .util .Set ;
5
4
6
5
import io .vertx .core .http .HttpHeaders ;
6
+ import io .vertx .core .http .impl .HttpUtils ;
7
7
import io .vertx .core .http .impl .MimeMapping ;
8
+ import io .vertx .core .net .impl .URIDecoder ;
8
9
import io .vertx .ext .web .RoutingContext ;
9
10
import io .vertx .ext .web .handler .StaticHandler ;
10
11
@@ -17,18 +18,24 @@ private RoutingUtils() throws IllegalAccessException {
17
18
/**
18
19
* Get the normalized and decoded path:
19
20
* - normalize based on RFC3986
20
- * - convert % encoded characters to their non encoded form (using {@link java.net.URI})
21
+ * - convert % encoded characters to their non encoded form (using {@link URIDecoder#decodeURIComponent})
22
+ * - remove relative dots in path
23
+ * - replace '\' with '/'
21
24
* - invalid if the path contains '?' (query section of the path)
22
25
*
23
26
* @param ctx the RoutingContext
24
27
* @return the normalized and decoded path or null if not valid
25
28
*/
26
29
public static String getNormalizedAndDecodedPath (RoutingContext ctx ) {
27
30
String normalizedPath = ctx .normalizedPath ();
28
- if (normalizedPath .contains ( "?" ) ) {
31
+ if (normalizedPath .indexOf ( '?' ) != - 1 ) {
29
32
return null ;
30
33
}
31
- return URI .create (normalizedPath ).getPath ();
34
+ if (normalizedPath .indexOf ('%' ) == -1 ) {
35
+ return normalizedPath ;
36
+ }
37
+ final String uriDecodedPath = URIDecoder .decodeURIComponent (normalizedPath );
38
+ return toUnixPathWithoutDots (uriDecodedPath );
32
39
}
33
40
34
41
/**
@@ -67,6 +74,10 @@ public static void compressIfNeeded(VertxHttpBuildTimeConfig config, Set<String>
67
74
}
68
75
}
69
76
77
+ private static String toUnixPathWithoutDots (String path ) {
78
+ return HttpUtils .removeDots (path .replace ('\\' , '/' ));
79
+ }
80
+
70
81
private static boolean isCompressed (Set <String > compressMediaTypes , String path ) {
71
82
if (compressMediaTypes .isEmpty ()) {
72
83
return false ;
0 commit comments