From 1619197851f6ab44611ee74a937f68e433ea007d Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Tue, 9 Jun 2015 15:44:41 -0700 Subject: [PATCH] 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 --- .../google/gerrit/server/config/GitWebConfig.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/config/GitWebConfig.java b/gerrit-server/src/main/java/com/google/gerrit/server/config/GitWebConfig.java index 158c8a8af1..00767a16e9 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/config/GitWebConfig.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/config/GitWebConfig.java @@ -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. //