Avoid caching invalid root directories

Closes gh-34111
This commit is contained in:
Juergen Hoeller 2025-01-12 18:00:10 +01:00
parent 7c4351ab0a
commit c48fec885c
1 changed files with 14 additions and 8 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@ -645,13 +645,15 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
}
}
if (currentPrefix != null) {
// A prefix match found, potentially to be turned into a common parent cache entry.
if (commonPrefix == null || !commonUnique || currentPrefix.length() > commonPrefix.length()) {
commonPrefix = currentPrefix;
existingPath = path;
}
else if (currentPrefix.equals(commonPrefix)) {
commonUnique = false;
if (checkPathWithinPackage(path.substring(currentPrefix.length()))) {
// A prefix match found, potentially to be turned into a common parent cache entry.
if (commonPrefix == null || !commonUnique || currentPrefix.length() > commonPrefix.length()) {
commonPrefix = currentPrefix;
existingPath = path;
}
else if (currentPrefix.equals(commonPrefix)) {
commonUnique = false;
}
}
}
else if (actualRootPath == null || path.length() > actualRootPath.length()) {
@ -1103,6 +1105,10 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
return (path.startsWith("/") ? path.substring(1) : path);
}
private static boolean checkPathWithinPackage(String path) {
return (path.contains("/") && !path.contains(ResourceUtils.JAR_URL_SEPARATOR));
}
/**
* Inner delegate class, avoiding a hard JBoss VFS API dependency at runtime.