Issue #5129 - Directories discovered via classpath glob are not valid

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2020-08-11 10:43:55 -05:00
parent 4a19ef4bb2
commit d91cab0354
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
3 changed files with 9 additions and 42 deletions

View File

@ -331,19 +331,12 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility
Resource resource = lib.addPath(entry);
if (LOG.isDebugEnabled())
LOG.debug("addJar - {}", resource);
if (resource.isDirectory())
String fnlc = resource.getName().toLowerCase(Locale.ENGLISH);
// don't check if this is a directory (prevents use of symlinks), see Bug 353165
if (isFileSupported(fnlc))
{
addURL(resource.getURI().toURL());
}
else
{
String fnlc = resource.getName().toLowerCase(Locale.ENGLISH);
// don't check if this is a directory (prevents use of symlinks), see Bug 353165
if (isFileSupported(fnlc))
{
String jar = URIUtil.encodeSpecific(resource.toString(), ",;");
addClassPath(jar);
}
String jar = URIUtil.encodeSpecific(resource.toString(), ",;");
addClassPath(jar);
}
}
catch (Exception ex)

View File

@ -1038,30 +1038,8 @@ public class WebInfConfiguration extends AbstractConfiguration
while (tokenizer.hasMoreTokens())
{
String token = tokenizer.nextToken().trim();
if (isGlobReference(token))
{
String dir = token.substring(0, token.length() - 2);
// Use directory
Resource dirResource = context.newResource(dir);
if (dirResource.exists() && dirResource.isDirectory())
{
// To obtain the list of files
String[] entries = dirResource.list();
if (entries != null)
{
Arrays.sort(entries);
for (String entry : entries)
{
Resource resource = dirResource.addPath(entry);
if (resource.isDirectory())
{
dirResources.add(resource);
}
}
}
}
}
else
// ignore glob references, they only refer to lists of jars/zips anyway
if (!isGlobReference(token))
{
Resource resource = context.newResource(token);
if (resource.exists() && resource.isDirectory())

View File

@ -133,12 +133,8 @@ public class WebAppContextExtraClasspathTest
Path extLibsDir = MavenTestingUtils.getTestResourcePathDir("ext");
extLibsDir = extLibsDir.toAbsolutePath();
List<Path> expectedPaths = Files.list(extLibsDir)
.filter((path) ->
{
if (Files.isDirectory(path))
return true;
return Files.isRegularFile(path) && path.toString().endsWith(".jar");
})
.filter(Files::isRegularFile)
.filter((path) -> path.toString().endsWith(".jar"))
.collect(Collectors.toList());
List<Path> actualPaths = new ArrayList<>();
for (URL url : webAppClassLoader.getURLs())