Avoid pattern misdetection in Tomcat "war:" URL separator

Issue: SPR-15332
(cherry picked from commit 012c56a)
This commit is contained in:
Juergen Hoeller 2017-03-16 18:55:49 +01:00
parent cfd9b3461f
commit 57c8c759ae
2 changed files with 14 additions and 15 deletions

View File

@ -284,9 +284,10 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
}
}
else {
// Only look for a pattern after a prefix here
// (to not get fooled by a pattern symbol in a strange prefix).
int prefixEnd = locationPattern.indexOf(":") + 1;
// Generally only look for a pattern after a prefix here,
// and on Tomcat only after the "*/" separator for its "war:" protocol.
int prefixEnd = (locationPattern.startsWith("war:") ? locationPattern.indexOf("*/") + 1 :
locationPattern.indexOf(":") + 1);
if (getPathMatcher().isPattern(locationPattern.substring(prefixEnd))) {
// a file pattern
return findPathMatchingResources(locationPattern);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@ -35,12 +35,6 @@ import java.net.URLConnection;
* object, which in turn allows one to obtain a {@code java.io.File} in the
* file system through its {@code getFile()} method.
*
* <p>The main reason for these utility methods for resource location handling
* is to support {@link Log4jConfigurer}, which must be able to resolve
* resource locations <i>before the logging system has been initialized</i>.
* Spring's {@code Resource} abstraction in the core package, on the other hand,
* already expects the logging system to be available.
*
* @author Juergen Hoeller
* @since 1.1.5
* @see org.springframework.core.io.Resource
@ -69,6 +63,9 @@ public abstract class ResourceUtils {
/** URL protocol for an entry from a jar file: "jar" */
public static final String URL_PROTOCOL_JAR = "jar";
/** URL protocol for an entry from a war file: "war" */
public static final String URL_PROTOCOL_WAR = "war";
/** URL protocol for an entry from a zip file: "zip" */
public static final String URL_PROTOCOL_ZIP = "zip";
@ -264,7 +261,7 @@ public abstract class ResourceUtils {
/**
* Determine whether the given URL points to a resource in the file system,
* that is, has protocol "file", "vfsfile" or "vfs".
* i.e. has protocol "file", "vfsfile" or "vfs".
* @param url the URL to check
* @return whether the URL has been identified as a file system URL
*/
@ -275,15 +272,16 @@ public abstract class ResourceUtils {
}
/**
* Determine whether the given URL points to a resource in a jar file,
* that is, has protocol "jar", "zip", "vfszip" or "wsjar".
* Determine whether the given URL points to a resource in a jar file.
* i.e. has protocol "jar", "war, ""zip", "vfszip" or "wsjar".
* @param url the URL to check
* @return whether the URL has been identified as a JAR URL
*/
public static boolean isJarURL(URL url) {
String protocol = url.getProtocol();
return (URL_PROTOCOL_JAR.equals(protocol) || URL_PROTOCOL_ZIP.equals(protocol) ||
URL_PROTOCOL_VFSZIP.equals(protocol) || URL_PROTOCOL_WSJAR.equals(protocol));
return (URL_PROTOCOL_JAR.equals(protocol) || URL_PROTOCOL_WAR.equals(protocol) ||
URL_PROTOCOL_ZIP.equals(protocol) || URL_PROTOCOL_VFSZIP.equals(protocol) ||
URL_PROTOCOL_WSJAR.equals(protocol));
}
/**