11/*
2- * Copyright 2002-2013 the original author or authors.
2+ * Copyright 2002-2014 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2222import java .util .Map ;
2323import java .util .Map .Entry ;
2424import java .util .Properties ;
25-
2625import javax .servlet .http .HttpServletRequest ;
2726
2827import org .apache .commons .logging .Log ;
2928import org .apache .commons .logging .LogFactory ;
29+
3030import org .springframework .util .LinkedMultiValueMap ;
3131import org .springframework .util .MultiValueMap ;
3232import org .springframework .util .StringUtils ;
@@ -181,11 +181,24 @@ public String getPathWithinServletMapping(HttpServletRequest request) {
181181 }
182182 else {
183183 // 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.
187184 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 ;
189202 }
190203 }
191204
@@ -217,7 +230,7 @@ public String getPathWithinApplication(HttpServletRequest request) {
217230 private String getRemainingPath (String requestUri , String mapping , boolean ignoreCase ) {
218231 int index1 = 0 ;
219232 int index2 = 0 ;
220- for ( ; (index1 < requestUri .length ()) && (index2 < mapping .length ()); index1 ++, index2 ++) {
233+ for (; (index1 < requestUri .length ()) && (index2 < mapping .length ()); index1 ++, index2 ++) {
221234 char c1 = requestUri .charAt (index1 );
222235 char c2 = mapping .charAt (index2 );
223236 if (c1 == ';' ) {
@@ -244,7 +257,7 @@ private String getRemainingPath(String requestUri, String mapping, boolean ignor
244257 else if (requestUri .charAt (index1 ) == ';' ) {
245258 index1 = requestUri .indexOf ('/' , index1 );
246259 }
247- return (index1 != -1 ) ? requestUri .substring (index1 ) : "" ;
260+ return (index1 != -1 ? requestUri .substring (index1 ) : "" ) ;
248261 }
249262
250263 /**
@@ -299,8 +312,7 @@ public String getServletPath(HttpServletRequest request) {
299312 if (servletPath == null ) {
300313 servletPath = request .getServletPath ();
301314 }
302- if (servletPath .length () > 1 && servletPath .endsWith ("/" ) &&
303- shouldRemoveTrailingServletPathSlash (request )) {
315+ if (servletPath .length () > 1 && servletPath .endsWith ("/" ) && shouldRemoveTrailingServletPathSlash (request )) {
304316 // On WebSphere, in non-compliant mode, for a "/foo/" case that would be "/foo"
305317 // on all other servlet containers: removing trailing slash, proceeding with
306318 // that remaining slash as final lookup path...
@@ -436,7 +448,6 @@ protected String determineEncoding(HttpServletRequest request) {
436448 * Remove ";" (semicolon) content from the given request URI if the
437449 * {@linkplain #setRemoveSemicolonContent(boolean) removeSemicolonContent}
438450 * property is set to "true". Note that "jssessionid" is always removed.
439- *
440451 * @param requestUri the request URI string to remove ";" content from
441452 * @return the updated URI string
442453 */
@@ -473,7 +484,6 @@ private String removeJsessionid(String requestUri) {
473484 * assumed the URL path from which the variables were extracted is already
474485 * decoded through a call to
475486 * {@link #getLookupPathForRequest(HttpServletRequest)}.
476- *
477487 * @param request current HTTP request
478488 * @param vars URI variables extracted from the URL path
479489 * @return the same Map or a new Map instance
@@ -498,7 +508,6 @@ public Map<String, String> decodePathVariables(HttpServletRequest request, Map<S
498508 * assumed the URL path from which the variables were extracted is already
499509 * decoded through a call to
500510 * {@link #getLookupPathForRequest(HttpServletRequest)}.
501- *
502511 * @param request current HTTP request
503512 * @param vars URI variables extracted from the URL path
504513 * @return the same Map or a new Map instance
0 commit comments