Closed
Description
in SpringBootVFS
@Override
protected List<String> list(URL url, String path) throws IOException {
String urlString = url.toString();
String baseUrlString = urlString.endsWith("/") ? urlString : urlString.concat("/");
Resource[] resources = resourceResolver.getResources(baseUrlString + "**/*.class");
return Stream.of(resources).map(resource -> preserveSubpackageName(baseUrlString, resource, path))
.collect(Collectors.toList());
}
private static String preserveSubpackageName(final String baseUrlString, final Resource resource,
final String rootPath) {
try {
return rootPath + (rootPath.endsWith("/") ? "" : "/")
+ resource.getURL().toString().substring(baseUrlString.length());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
consider url may be containes none asccii charctor; such as chinese path.
the url.toString() return URLEncode result,
so the baseUrlString.length() should be grater than resource.getURL();
The bug exists in following code:
// if baseUrlString containes Space character, the baseUrlString.length() > resource.getURL().toString().length() is True
// so there throw StringIndexOutOfBoundsException
return rootPath + (rootPath.endsWith("/") ? "" : "/")
+ resource.getURL().toString().substring(baseUrlString.length());