1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
22
22
import java .util .Map ;
23
23
import java .util .Map .Entry ;
24
24
import java .util .Properties ;
25
-
26
25
import javax .servlet .http .HttpServletRequest ;
27
26
28
27
import org .apache .commons .logging .Log ;
29
28
import org .apache .commons .logging .LogFactory ;
29
+
30
30
import org .springframework .util .LinkedMultiValueMap ;
31
31
import org .springframework .util .MultiValueMap ;
32
32
import org .springframework .util .StringUtils ;
@@ -181,11 +181,24 @@ public String getPathWithinServletMapping(HttpServletRequest request) {
181
181
}
182
182
else {
183
183
// Special case: URI is different from servlet path.
184
- // Can happen e.g. with index page: URI="/", servletPath="/index.html"
185
- // Use path info if available, as it indicates an index page within
186
- // a servlet mapping. Otherwise, use the full servlet path.
187
184
String pathInfo = request .getPathInfo ();
188
- return (pathInfo != null ? pathInfo : servletPath );
185
+ if (pathInfo != null ) {
186
+ // Use path info if available. Indicates index page within a servlet mapping?
187
+ // e.g. with index page: URI="/", servletPath="/index.html"
188
+ return pathInfo ;
189
+ }
190
+ if (!this .urlDecode ) {
191
+ // No path info... (not mapped by prefix, nor by extension, nor "/*")
192
+ // For the default servlet mapping (i.e. "/"), urlDecode=false can
193
+ // cause issues since getServletPath() returns a decoded path.
194
+ // If decoding pathWithinApp yields a match just use pathWithinApp.
195
+ path = getRemainingPath (decodeInternal (request , pathWithinApp ), servletPath , false );
196
+ if (path != null ) {
197
+ return pathWithinApp ;
198
+ }
199
+ }
200
+ // Otherwise, use the full servlet path.
201
+ return servletPath ;
189
202
}
190
203
}
191
204
@@ -217,7 +230,7 @@ public String getPathWithinApplication(HttpServletRequest request) {
217
230
private String getRemainingPath (String requestUri , String mapping , boolean ignoreCase ) {
218
231
int index1 = 0 ;
219
232
int index2 = 0 ;
220
- for ( ; (index1 < requestUri .length ()) && (index2 < mapping .length ()); index1 ++, index2 ++) {
233
+ for (; (index1 < requestUri .length ()) && (index2 < mapping .length ()); index1 ++, index2 ++) {
221
234
char c1 = requestUri .charAt (index1 );
222
235
char c2 = mapping .charAt (index2 );
223
236
if (c1 == ';' ) {
@@ -244,7 +257,7 @@ private String getRemainingPath(String requestUri, String mapping, boolean ignor
244
257
else if (requestUri .charAt (index1 ) == ';' ) {
245
258
index1 = requestUri .indexOf ('/' , index1 );
246
259
}
247
- return (index1 != -1 ) ? requestUri .substring (index1 ) : "" ;
260
+ return (index1 != -1 ? requestUri .substring (index1 ) : "" ) ;
248
261
}
249
262
250
263
/**
@@ -299,8 +312,7 @@ public String getServletPath(HttpServletRequest request) {
299
312
if (servletPath == null ) {
300
313
servletPath = request .getServletPath ();
301
314
}
302
- if (servletPath .length () > 1 && servletPath .endsWith ("/" ) &&
303
- shouldRemoveTrailingServletPathSlash (request )) {
315
+ if (servletPath .length () > 1 && servletPath .endsWith ("/" ) && shouldRemoveTrailingServletPathSlash (request )) {
304
316
// On WebSphere, in non-compliant mode, for a "/foo/" case that would be "/foo"
305
317
// on all other servlet containers: removing trailing slash, proceeding with
306
318
// that remaining slash as final lookup path...
@@ -436,7 +448,6 @@ protected String determineEncoding(HttpServletRequest request) {
436
448
* Remove ";" (semicolon) content from the given request URI if the
437
449
* {@linkplain #setRemoveSemicolonContent(boolean) removeSemicolonContent}
438
450
* property is set to "true". Note that "jssessionid" is always removed.
439
- *
440
451
* @param requestUri the request URI string to remove ";" content from
441
452
* @return the updated URI string
442
453
*/
@@ -473,7 +484,6 @@ private String removeJsessionid(String requestUri) {
473
484
* assumed the URL path from which the variables were extracted is already
474
485
* decoded through a call to
475
486
* {@link #getLookupPathForRequest(HttpServletRequest)}.
476
- *
477
487
* @param request current HTTP request
478
488
* @param vars URI variables extracted from the URL path
479
489
* @return the same Map or a new Map instance
@@ -498,7 +508,6 @@ public Map<String, String> decodePathVariables(HttpServletRequest request, Map<S
498
508
* assumed the URL path from which the variables were extracted is already
499
509
* decoded through a call to
500
510
* {@link #getLookupPathForRequest(HttpServletRequest)}.
501
- *
502
511
* @param request current HTTP request
503
512
* @param vars URI variables extracted from the URL path
504
513
* @return the same Map or a new Map instance
0 commit comments