Skip to content

Commit b398216

Browse files
committed
Fail proactively if lookupPath not in requestUri
Closes gh-22851
1 parent b5327ef commit b398216

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -30,6 +30,7 @@
3030
import org.apache.commons.logging.LogFactory;
3131

3232
import org.springframework.lang.Nullable;
33+
import org.springframework.util.Assert;
3334
import org.springframework.web.filter.GenericFilterBean;
3435
import org.springframework.web.util.UrlPathHelper;
3536

@@ -96,6 +97,10 @@ private void initLookupPath(ResourceUrlProvider urlProvider) {
9697
String requestUri = pathHelper.getRequestUri(this);
9798
String lookupPath = pathHelper.getLookupPathForRequest(this);
9899
this.indexLookupPath = requestUri.lastIndexOf(lookupPath);
100+
Assert.isTrue(this.indexLookupPath != -1, () ->
101+
"Failed to find lookupPath '" + lookupPath + "' within requestUri '" + requestUri + ". " +
102+
"Does the path have invalid encoded characters " +
103+
"for characterEncoding=" + getRequest().getCharacterEncoding() + "?");
99104
this.prefixLookupPath = requestUri.substring(0, this.indexLookupPath);
100105
if ("/".equals(lookupPath) && !"/".equals(requestUri)) {
101106
String contextPath = pathHelper.getContextPath(this);

0 commit comments

Comments
 (0)