Skip to content

Commit 57c8c75

Browse files
committed
Avoid pattern misdetection in Tomcat "war:" URL separator
Issue: SPR-15332 (cherry picked from commit 012c56a)
1 parent cfd9b34 commit 57c8c75

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,10 @@ public Resource[] getResources(String locationPattern) throws IOException {
284284
}
285285
}
286286
else {
287-
// Only look for a pattern after a prefix here
288-
// (to not get fooled by a pattern symbol in a strange prefix).
289-
int prefixEnd = locationPattern.indexOf(":") + 1;
287+
// Generally only look for a pattern after a prefix here,
288+
// and on Tomcat only after the "*/" separator for its "war:" protocol.
289+
int prefixEnd = (locationPattern.startsWith("war:") ? locationPattern.indexOf("*/") + 1 :
290+
locationPattern.indexOf(":") + 1);
290291
if (getPathMatcher().isPattern(locationPattern.substring(prefixEnd))) {
291292
// a file pattern
292293
return findPathMatchingResources(locationPattern);

spring-core/src/main/java/org/springframework/util/ResourceUtils.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,12 +35,6 @@
3535
* object, which in turn allows one to obtain a {@code java.io.File} in the
3636
* file system through its {@code getFile()} method.
3737
*
38-
* <p>The main reason for these utility methods for resource location handling
39-
* is to support {@link Log4jConfigurer}, which must be able to resolve
40-
* resource locations <i>before the logging system has been initialized</i>.
41-
* Spring's {@code Resource} abstraction in the core package, on the other hand,
42-
* already expects the logging system to be available.
43-
*
4438
* @author Juergen Hoeller
4539
* @since 1.1.5
4640
* @see org.springframework.core.io.Resource
@@ -69,6 +63,9 @@ public abstract class ResourceUtils {
6963
/** URL protocol for an entry from a jar file: "jar" */
7064
public static final String URL_PROTOCOL_JAR = "jar";
7165

66+
/** URL protocol for an entry from a war file: "war" */
67+
public static final String URL_PROTOCOL_WAR = "war";
68+
7269
/** URL protocol for an entry from a zip file: "zip" */
7370
public static final String URL_PROTOCOL_ZIP = "zip";
7471

@@ -264,7 +261,7 @@ public static File getFile(URI resourceUri, String description) throws FileNotFo
264261

265262
/**
266263
* Determine whether the given URL points to a resource in the file system,
267-
* that is, has protocol "file", "vfsfile" or "vfs".
264+
* i.e. has protocol "file", "vfsfile" or "vfs".
268265
* @param url the URL to check
269266
* @return whether the URL has been identified as a file system URL
270267
*/
@@ -275,15 +272,16 @@ public static boolean isFileURL(URL url) {
275272
}
276273

277274
/**
278-
* Determine whether the given URL points to a resource in a jar file,
279-
* that is, has protocol "jar", "zip", "vfszip" or "wsjar".
275+
* Determine whether the given URL points to a resource in a jar file.
276+
* i.e. has protocol "jar", "war, ""zip", "vfszip" or "wsjar".
280277
* @param url the URL to check
281278
* @return whether the URL has been identified as a JAR URL
282279
*/
283280
public static boolean isJarURL(URL url) {
284281
String protocol = url.getProtocol();
285-
return (URL_PROTOCOL_JAR.equals(protocol) || URL_PROTOCOL_ZIP.equals(protocol) ||
286-
URL_PROTOCOL_VFSZIP.equals(protocol) || URL_PROTOCOL_WSJAR.equals(protocol));
282+
return (URL_PROTOCOL_JAR.equals(protocol) || URL_PROTOCOL_WAR.equals(protocol) ||
283+
URL_PROTOCOL_ZIP.equals(protocol) || URL_PROTOCOL_VFSZIP.equals(protocol) ||
284+
URL_PROTOCOL_WSJAR.equals(protocol));
287285
}
288286

289287
/**

0 commit comments

Comments
 (0)