Skip to content

Commit 350014b

Browse files
committed
[bugfix] Fix an issue with spaces in Windows file paths when locating conf.xml
1 parent 53d1e8a commit 350014b

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

  • exist-start/src/main/java/org/exist/start

exist-start/src/main/java/org/exist/start/Main.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ public void runEx(String[] args) throws StartException {
312312
Thread.currentThread().setContextClassLoader(cl);
313313

314314
// Invoke main class using new classloader.
315+
args = cleanupArgs(args);
315316
try {
316317
invokeMain(cl, _classname, args);
317318
} catch (final Exception e) {
@@ -320,6 +321,34 @@ public void runEx(String[] args) throws StartException {
320321
}
321322
}
322323

324+
public static String[] cleanupArgs(final String[] args) {
325+
if (args == null) {
326+
return null;
327+
}
328+
if (args.length == 0) {
329+
return args;
330+
}
331+
332+
final String[] nargs = new String[args.length];
333+
for (int i = 0; i < args.length; i++) {
334+
String arg = args[i];
335+
336+
if (arg.startsWith("\"") && arg.indexOf('\"', 1) > -1 && (arg.endsWith("conf.xml") || arg.endsWith("log4j2.xml"))) {
337+
// String that starts with quote, has a quote somewhere in it, and ends with conf.xml or log4j2.xml - such invalid strings can be produced by startup.bat on Windows
338+
arg = arg.replaceAll("\"", "");
339+
}
340+
341+
if (arg.indexOf('\\') != -1 && arg.indexOf('\\') < arg.indexOf('/') && (arg.endsWith("conf.xml") || arg.endsWith("log4j2.xml"))) {
342+
// String that contains both '\' path separators followed by `/` path separators, and ends with conf.xml or log4j2.xml - such invalid strings can be produced by startup.bat on Windows
343+
arg = arg.replaceAll("/", "\\\\");
344+
}
345+
346+
nargs[i] = arg;
347+
}
348+
349+
return nargs;
350+
}
351+
323352
private Optional<String> getFromSysPropOrEnv(final String sysPropName, final String envVarName) {
324353
Optional<String> value = Optional.ofNullable(System.getProperty(sysPropName));
325354
if (!value.isPresent()) {

0 commit comments

Comments
 (0)