Skip to content

Commit a7dc485

Browse files
committed
Normalize resource URL in ResourceServlet
Issue: SPR-14946
1 parent bd282e6 commit a7dc485

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/ResourceServlet.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.web.servlet;
1818

1919
import java.io.IOException;
20-
2120
import javax.servlet.RequestDispatcher;
2221
import javax.servlet.ServletException;
2322
import javax.servlet.http.HttpServletRequest;
@@ -271,18 +270,18 @@ private void doInclude(HttpServletRequest request, HttpServletResponse response,
271270
if (this.contentType != null) {
272271
response.setContentType(this.contentType);
273272
}
274-
String[] resourceUrls =
275-
StringUtils.tokenizeToStringArray(resourceUrl, RESOURCE_URL_DELIMITERS);
276-
for (int i = 0; i < resourceUrls.length; i++) {
273+
String[] resourceUrls = StringUtils.tokenizeToStringArray(resourceUrl, RESOURCE_URL_DELIMITERS);
274+
for (String url : resourceUrls) {
275+
String path = StringUtils.cleanPath(url);
277276
// check whether URL matches allowed resources
278-
if (this.allowedResources != null && !this.pathMatcher.match(this.allowedResources, resourceUrls[i])) {
279-
throw new ServletException("Resource [" + resourceUrls[i] +
277+
if (this.allowedResources != null && !this.pathMatcher.match(this.allowedResources, path)) {
278+
throw new ServletException("Resource [" + path +
280279
"] does not match allowed pattern [" + this.allowedResources + "]");
281280
}
282281
if (logger.isDebugEnabled()) {
283-
logger.debug("Including resource [" + resourceUrls[i] + "]");
282+
logger.debug("Including resource [" + path + "]");
284283
}
285-
RequestDispatcher rd = request.getRequestDispatcher(resourceUrls[i]);
284+
RequestDispatcher rd = request.getRequestDispatcher(path);
286285
rd.include(request, response);
287286
}
288287
}

0 commit comments

Comments
 (0)