Skip to content

Commit a94aafd

Browse files
committed
Previous hack attempt would fail on Windows
Instead use a little bit of code from UriUtil, which has to be duplicated since it is not available from here.
1 parent be63410 commit a94aafd

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

java/org/apache/catalina/startup/CatalinaProperties.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ private static void loadProperties() {
7272
try {
7373
String configUrl = System.getProperty("catalina.config");
7474
if (configUrl != null) {
75-
if (configUrl.indexOf(':') == -1) {
76-
// No ':'. Must be a file name rather than a URL
77-
fileName = configUrl;
78-
} else {
75+
boolean isAbsoluteUri = isAbsoluteURI(configUrl);
76+
if (isAbsoluteUri) {
7977
is = new URI(configUrl).toURL().openStream();
78+
} else {
79+
// Not an absolute URI. Must be a file name.
80+
fileName = configUrl;
8081
}
8182
}
8283
} catch (Throwable t) {
@@ -137,6 +138,34 @@ private static void loadProperties() {
137138
}
138139

139140

141+
private static boolean isSchemeChar(char c) {
142+
return Character.isLetterOrDigit(c) || c == '+' || c == '-' || c == '.';
143+
}
144+
145+
146+
private static boolean isAbsoluteURI(String path) {
147+
// Special case as only a single /
148+
if (path.startsWith("file:/")) {
149+
return true;
150+
}
151+
152+
// Start at the beginning of the path and skip over any valid protocol
153+
// characters
154+
int i = 0;
155+
while (i < path.length() && isSchemeChar(path.charAt(i))) {
156+
i++;
157+
}
158+
// Need at least one protocol character. False positives with Windows
159+
// drives such as C:/... will be caught by the later test for "://"
160+
if (i == 0) {
161+
return false;
162+
}
163+
// path starts with something that might be a protocol. Look for a
164+
// following "://"
165+
return i + 2 < path.length() && path.charAt(i++) == ':' && path.charAt(i++) == '/' && path.charAt(i) == '/';
166+
}
167+
168+
140169
// Copied from ExceptionUtils since that class is not visible during start
141170
private static void handleThrowable(Throwable t) {
142171
if (t instanceof VirtualMachineError) {

0 commit comments

Comments
 (0)