Fix start-dev mode on Windows by avoiding backslashes escaping expressions

Closes #17413
This commit is contained in:
Alexander Schwartz 2023-03-02 17:01:30 +01:00 committed by Bruno Oliveira da Silva
parent 4bfa3c7a1a
commit 4cf5c11020

View file

@ -107,13 +107,23 @@ public final class Database {
@Override
public String apply(String alias) {
if ("dev-file".equalsIgnoreCase(alias)) {
return addH2NonKeywords("jdbc:h2:file:${kc.home.dir:${kc.db-url-path:" + System.getProperty("user.home") + "}}" + File.separator + "${kc.data.dir:data}"
+ File.separator + "h2" + File.separator
return addH2NonKeywords("jdbc:h2:file:${kc.home.dir:${kc.db-url-path:" + escapeReplacements(System.getProperty("user.home")) + "}}" + escapeReplacements(File.separator) + "${kc.data.dir:data}"
+ escapeReplacements(File.separator) + "h2" + escapeReplacements(File.separator)
+ "keycloakdb${kc.db-url-properties:;;AUTO_SERVER=TRUE}");
}
return addH2NonKeywords("jdbc:h2:mem:keycloakdb${kc.db-url-properties:}");
}
private String escapeReplacements(String snippet) {
if (File.separator.equals("\\")) {
// SmallRye will do replacements of "${...}", but a "\" must not escape such an expression.
// As we nest multiple expressions, and each nested expression must re-escape the backslashes,
// the simplest way is to replace a backslash with a slash, as those are processed nicely on Windows.
return snippet.replace("\\", "/");
}
return snippet;
}
/**
* Starting with H2 version 2.x, marking "VALUE" as a non-keyword is necessary as some columns are named "VALUE" in the Keycloak schema.
* <p />