GitWebConfig: Fix check for set-to-empty-string
Config.getString returns null if the string is set to an empty value. This is, depending on your point of view, either a bug in JGit or defined but confusing behavior. Alas, the only reliable way of checking for the empty string in current JGit is to look for the value as a string list. Change-Id: I7603af40699516274f1063d1354f3234fdb6a3d9
This commit is contained in:
parent
adca960f65
commit
1619197851
@ -17,6 +17,7 @@ package com.google.gerrit.server.config;
|
||||
import static java.nio.file.Files.isExecutable;
|
||||
import static java.nio.file.Files.isRegularFile;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gerrit.common.data.GitWebType;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@ -30,6 +31,14 @@ import java.nio.file.Paths;
|
||||
public class GitWebConfig {
|
||||
private static final Logger log = LoggerFactory.getLogger(GitWebConfig.class);
|
||||
|
||||
private static boolean isEmptyString(Config cfg, String section,
|
||||
String subsection, String name) {
|
||||
// This is currently the only way to check for the empty string in a JGit
|
||||
// config. Fun!
|
||||
String[] values = cfg.getStringList(section, subsection, name);
|
||||
return values.length > 0 && Strings.isNullOrEmpty(values[0]);
|
||||
}
|
||||
|
||||
private final String url;
|
||||
private final Path gitweb_cgi;
|
||||
private final Path gitweb_css;
|
||||
@ -95,8 +104,8 @@ public class GitWebConfig {
|
||||
type = null;
|
||||
}
|
||||
|
||||
if ((cfgUrl != null && cfgUrl.isEmpty())
|
||||
|| (cfgCgi != null && cfgCgi.isEmpty())) {
|
||||
if (isEmptyString(cfg, "gitweb", null, "url")
|
||||
|| isEmptyString(cfg, "gitweb", null, "cgi")) {
|
||||
// Either setting was explicitly set to the empty string disabling
|
||||
// gitweb for this server. Disable the configuration.
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user