Skip to content

Commit e2aa117

Browse files
Skarafazbclozel
authored andcommitted
Find exact matches in WebJarsResourceResolver
Prior to this commit, resolving resources from webjars using the `WebJarAssetLocator.getFullPath` could lead to multiple candidates, since this method is trying to find *any* resource matching that path under the given webjar location. This commit replaces that call with `WebJarAssetLocator.getFullPathExact`, which avoids those multiple matches and only resolves resources if the given path is exact. Issue: SPR-15526
1 parent 8deec95 commit e2aa117

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

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

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -17,9 +17,9 @@
1717
package org.springframework.web.servlet.resource;
1818

1919
import java.util.List;
20+
2021
import javax.servlet.http.HttpServletRequest;
2122

22-
import org.webjars.MultipleMatchesException;
2323
import org.webjars.WebJarAssetLocator;
2424

2525
import org.springframework.core.io.Resource;
@@ -99,26 +99,16 @@ protected String resolveUrlPathInternal(String resourceUrlPath,
9999
}
100100

101101
protected String findWebJarResourcePath(String path) {
102-
try {
103-
int startOffset = (path.startsWith("/") ? 1 : 0);
104-
int endOffset = path.indexOf("/", 1);
105-
if (endOffset != -1) {
106-
String webjar = path.substring(startOffset, endOffset);
107-
String partialPath = path.substring(endOffset);
108-
String webJarPath = webJarAssetLocator.getFullPath(webjar, partialPath);
102+
int startOffset = (path.startsWith("/") ? 1 : 0);
103+
int endOffset = path.indexOf("/", 1);
104+
if (endOffset != -1) {
105+
String webjar = path.substring(startOffset, endOffset);
106+
String partialPath = path.substring(endOffset + 1);
107+
String webJarPath = webJarAssetLocator.getFullPathExact(webjar, partialPath);
108+
if (webJarPath != null) {
109109
return webJarPath.substring(WEBJARS_LOCATION_LENGTH);
110110
}
111111
}
112-
catch (MultipleMatchesException ex) {
113-
if (logger.isWarnEnabled()) {
114-
logger.warn("WebJar version conflict for \"" + path + "\"", ex);
115-
}
116-
}
117-
catch (IllegalArgumentException ex) {
118-
if (logger.isTraceEnabled()) {
119-
logger.trace("No WebJar resource found for \"" + path + "\"");
120-
}
121-
}
122112
return null;
123113
}
124114

0 commit comments

Comments
 (0)