Skip to content

Commit 8d0b72b

Browse files
committed
Fail proactively if lookupPath not in requestUri
Closes gh-22851
1 parent 4c49833 commit 8d0b72b

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.commons.logging.Log;
3030
import org.apache.commons.logging.LogFactory;
3131

32+
import org.springframework.util.Assert;
3233
import org.springframework.web.filter.GenericFilterBean;
3334
import org.springframework.web.util.UrlPathHelper;
3435

@@ -93,6 +94,10 @@ private void initLookupPath(ResourceUrlProvider urlProvider) {
9394
String requestUri = pathHelper.getRequestUri(this);
9495
String lookupPath = pathHelper.getLookupPathForRequest(this);
9596
this.indexLookupPath = requestUri.lastIndexOf(lookupPath);
97+
Assert.isTrue(this.indexLookupPath != -1,
98+
"Failed to find lookupPath '" + lookupPath + "' within requestUri '" + requestUri + ". " +
99+
"Does the path have invalid encoded characters " +
100+
"for characterEncoding=" + getRequest().getCharacterEncoding() + "?");
96101
this.prefixLookupPath = requestUri.substring(0, this.indexLookupPath);
97102
if ("/".equals(lookupPath) && !"/".equals(requestUri)) {
98103
String contextPath = pathHelper.getContextPath(this);

0 commit comments

Comments
 (0)