1818
1919package io .undertow .servlet .spec ;
2020
21+ import io .undertow .UndertowOptions ;
2122import io .undertow .security .api .SecurityContext ;
2223import io .undertow .security .idm .Account ;
2324import io .undertow .server .HttpServerExchange ;
5455import java .io .UnsupportedEncodingException ;
5556import java .net .InetAddress ;
5657import java .net .InetSocketAddress ;
58+ import java .net .URLDecoder ;
5759import java .nio .charset .Charset ;
5860import java .nio .charset .StandardCharsets ;
5961import java .nio .charset .UnsupportedCharsetException ;
@@ -286,16 +288,29 @@ public String getMethod() {
286288
287289 @ Override
288290 public String getPathInfo () {
289- ServletPathMatch match = exchange .getAttachment (ServletRequestContext .ATTACHMENT_KEY ).getServletPathMatch ();
290- if (match != null ) {
291- return match .getRemaining ();
291+ final ServletPathMatch match = exchange .getAttachment (ServletRequestContext .ATTACHMENT_KEY ).getServletPathMatch ();
292+ return match != null ? decodeURL (match .getRemaining ()) : null ;
293+ }
294+
295+ private String decodeURL (final String s ) {
296+ try {
297+ return s != null && s .length () > 0 ? URLDecoder .decode (s , getURLEncoding ()) : s ;
298+ } catch (UnsupportedEncodingException ignored ) {
299+ throw new IllegalStateException (); // cannot happen
292300 }
293- return null ;
301+ }
302+
303+ private String getURLEncoding () {
304+ return exchange .getConnection ().getUndertowOptions ().get (UndertowOptions .URL_CHARSET , StandardCharsets .UTF_8 .name ());
294305 }
295306
296307 @ Override
297308 public String getPathTranslated () {
298- return getRealPath (getPathInfo ());
309+ ServletPathMatch match = exchange .getAttachment (ServletRequestContext .ATTACHMENT_KEY ).getServletPathMatch ();
310+ if (match != null ) {
311+ return getRealPath (match .getRemaining ());
312+ }
313+ return null ;
299314 }
300315
301316 @ Override
@@ -413,11 +428,8 @@ public StringBuffer getRequestURL() {
413428
414429 @ Override
415430 public String getServletPath () {
416- ServletPathMatch match = exchange .getAttachment (ServletRequestContext .ATTACHMENT_KEY ).getServletPathMatch ();
417- if (match != null ) {
418- return match .getMatched ();
419- }
420- return "" ;
431+ final ServletPathMatch match = exchange .getAttachment (ServletRequestContext .ATTACHMENT_KEY ).getServletPathMatch ();
432+ return match != null ? decodeURL (match .getMatched ()) : "" ;
421433 }
422434
423435 @ Override
@@ -1156,7 +1168,11 @@ public String getOriginalServletPath() {
11561168 if (uri != null ) {
11571169 return uri ;
11581170 }
1159- return getServletPath ();
1171+ ServletPathMatch match = exchange .getAttachment (ServletRequestContext .ATTACHMENT_KEY ).getServletPathMatch ();
1172+ if (match != null ) {
1173+ return match .getMatched ();
1174+ }
1175+ return "" ;
11601176 }
11611177
11621178 public String getOriginalPathInfo () {
@@ -1168,7 +1184,11 @@ public String getOriginalPathInfo() {
11681184 if (uri != null ) {
11691185 return uri ;
11701186 }
1171- return getPathInfo ();
1187+ ServletPathMatch match = exchange .getAttachment (ServletRequestContext .ATTACHMENT_KEY ).getServletPathMatch ();
1188+ if (match != null ) {
1189+ return match .getRemaining ();
1190+ }
1191+ return null ;
11721192 }
11731193
11741194 public String getOriginalContextPath () {
0 commit comments