Escape values written to mvnd.properties

This commit is contained in:
Peter Palaga
2020-07-30 16:00:12 +02:00
parent 0c9f3bd22c
commit bc3f341dc1

View File

@@ -93,8 +93,8 @@ public class Installer {
static void writeMvndProperties(Path mvndPropsPath, Path mvndHome, Path javaHome) {
LOG.info("Writing {}", mvndPropsPath);
final String template = readTemplate();
final String javaHomeLine = javaHome == null ? "" : "java.home = " + javaHome.toString();
final String content = String.format(template, mvndHome.toString(), javaHomeLine);
final String javaHomeLine = javaHome == null ? "" : "java.home = " + escape(javaHome.toString());
final String content = String.format(template, escape(mvndHome.toString()), javaHomeLine);
try {
Files.write(mvndPropsPath, content.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
@@ -102,6 +102,10 @@ public class Installer {
}
}
static String escape(String string) {
return string.replace("\\", "\\\\");
}
static String readTemplate() {
try (InputStream in = Installer.class.getResourceAsStream("mvnd.properties.template");
ByteArrayOutputStream out = new ByteArrayOutputStream(256)) {