Skip to content

Commit c1869f4

Browse files
committed
Adds double check if resource exists
1 parent 17d5e39 commit c1869f4

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

plugins/convention/src/main/java/org/apache/struts2/convention/ConventionUnknownHandler.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
import javax.servlet.ServletContext;
3737
import java.net.MalformedURLException;
3838
import java.util.*;
39+
import java.net.URL;
40+
import java.util.Collections;
41+
import java.util.HashMap;
42+
import java.util.LinkedHashMap;
43+
import java.util.List;
44+
import java.util.Map;
3945

4046
/**
4147
* <p>
@@ -313,16 +319,18 @@ protected Result findResult(String path, String resultCode, String ext, ActionCo
313319
try {
314320
LOG.trace("Checking ServletContext for {}", path);
315321

316-
if (servletContext.getResource(path) != null) {
317-
LOG.trace("Found");
322+
URL resource = servletContext.getResource(path);
323+
if (resource != null && resource.getPath().endsWith(path)) {
324+
LOG.trace("Found resource {}", resource);
318325
return buildResult(path, resultCode, resultsByExtension.get(ext), actionContext);
319326
}
320327

321328
LOG.trace("Checking ClassLoader for {}", path);
322329

323330
String classLoaderPath = path.startsWith("/") ? path.substring(1, path.length()) : path;
324-
if (ClassLoaderUtil.getResource(classLoaderPath, getClass()) != null) {
325-
LOG.trace("Found");
331+
resource = ClassLoaderUtil.getResource(classLoaderPath, getClass());
332+
if (resource != null && resource.getPath().endsWith(classLoaderPath)) {
333+
LOG.trace("Found resource {}", resource);
326334
return buildResult(path, resultCode, resultsByExtension.get(ext), actionContext);
327335
}
328336
} catch (MalformedURLException e) {

0 commit comments

Comments
 (0)