Merge "Assume correct relative or absolute URL from Weblink provider" into stable-2.14

This commit is contained in:
David Pursehouse
2018-09-06 23:55:15 +00:00
committed by Gerrit Code Review
3 changed files with 16 additions and 7 deletions

View File

@@ -35,6 +35,8 @@ import com.google.gerrit.extensions.webui.TagWebLink;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.jgit.lib.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -179,7 +181,11 @@ public class GitwebConfig {
private final GitwebType type;
@Inject
GitwebConfig(GitwebCgiConfig cgiConfig, @GerritServerConfig Config cfg) {
GitwebConfig(
GitwebCgiConfig cgiConfig,
@GerritServerConfig Config cfg,
@Nullable @CanonicalWebUrl String gerritUrl)
throws MalformedURLException {
if (isDisabled(cfg)) {
type = null;
url = null;
@@ -192,7 +198,14 @@ public class GitwebConfig {
// Use an externally managed gitweb instance, and not an internal one.
url = cfgUrl;
} else {
url = firstNonNull(cfgUrl, "gitweb");
String baseGerritUrl;
if (gerritUrl != null) {
URL u = new URL(gerritUrl);
baseGerritUrl = u.getPath();
} else {
baseGerritUrl = "/";
}
url = firstNonNull(cfgUrl, baseGerritUrl + "gitweb");
}
}
}

View File

@@ -81,10 +81,6 @@
return;
}
if (!/^https?\:\/\//.test(webLink)) {
webLink = '../../' + webLink;
}
return webLink;
},

View File

@@ -56,7 +56,7 @@ limitations under the License.
assert.isOk(element._computeShowWebLink(element.change,
element.commitInfo, element.serverConfig));
assert.equal(element._computeWebLink(element.change, element.commitInfo,
element.serverConfig), '../../link-url');
element.serverConfig), 'link-url');
});
test('does not relativize web links that begin with scheme', function() {