From 9d55884a86dc30693dc3e27afaa44d40dd7e94e1 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 1 May 2019 03:57:44 -0400 Subject: [PATCH] Fail proactively if lookupPath not in requestUri Closes gh-22851 --- .../web/servlet/resource/ResourceUrlEncodingFilter.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java index d2e70557f4f..e6def68acea 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.lang.Nullable; +import org.springframework.util.Assert; import org.springframework.web.filter.GenericFilterBean; import org.springframework.web.util.UrlPathHelper; @@ -96,6 +97,10 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean { String requestUri = pathHelper.getRequestUri(this); String lookupPath = pathHelper.getLookupPathForRequest(this); this.indexLookupPath = requestUri.lastIndexOf(lookupPath); + Assert.isTrue(this.indexLookupPath != -1, () -> + "Failed to find lookupPath '" + lookupPath + "' within requestUri '" + requestUri + ". " + + "Does the path have invalid encoded characters " + + "for characterEncoding=" + getRequest().getCharacterEncoding() + "?"); this.prefixLookupPath = requestUri.substring(0, this.indexLookupPath); if ("/".equals(lookupPath) && !"/".equals(requestUri)) { String contextPath = pathHelper.getContextPath(this);