[fixes #2960] [installer] Fix issue with weird chars in eclipse path

Lombok used to attempt to escape 'weird' chars (using a whitelist of chars that need no escaping) when writing out eclipse.ini.
However, there _is no_ escaping mechanism available there. Instead, apparently eclipse/java just reads the chars appearing after
the `-javaagent:` prefix as literally as possible. Therefore, just.. don't escape, and pray. Spaces, colons, and ats have all been confirmed
as working correctly when rendering them literally, and as failing when you attempt to escape them.
This commit is contained in:
Reinier Zwitserloot committed 2021-09-15 15:57:36 +02:00
1 parent 69c928a629
commit 0d7260d052
2 files changed
+3 -13

No files matched your search

@@ -64,16 +64,4 @@ public abstract class IdeLocation {
return x == null ? p.getPath() : x;
}
}
private static final String LEGAL_PATH_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_/";
private static final String LEGAL_PATH_CHARS_WINDOWS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,/;'[]{}!@#$^&()-_+= :\\";
public static String escapePath(String path) {
StringBuilder out = new StringBuilder();
String legalChars = OsUtils.getOS() == OsUtils.OS.UNIX ? LEGAL_PATH_CHARS : LEGAL_PATH_CHARS_WINDOWS;
for (char c : path.toCharArray()) {
if (legalChars.indexOf(c) == -1) out.append('\\');
out.append(c);
}
return out.toString();
}
}
@@ -347,8 +347,10 @@ public final class EclipseProductLocation extends IdeLocation {
pathPrefix = pathToLombokJarPrefix;
}
// NB: You may be tempted to escape this, but don't; there is no possibility to escape this, but
// eclipse/java reads the string following the colon in 'raw' fashion. Spaces, colons - all works fine.
newContents.append(String.format(
"-javaagent:%s", escapePath(pathPrefix + "lombok.jar"))).append(OS_NEWLINE);
"-javaagent:%s", pathPrefix + "lombok.jar")).append(OS_NEWLINE);
FileOutputStream fos = new FileOutputStream(eclipseIniPath);
try {