diff options
author | Sven Selberg <svense@axis.com> | 2018-06-28 10:29:44 +0200 |
---|---|---|
committer | David Pursehouse <dpursehouse@collab.net> | 2018-09-06 11:33:40 +0000 |
commit | 1ed12c156bfbcee2f997bcce4984dd39a7c85764 (patch) | |
tree | 82533ef6688690bf34fbe98ec06a3351e95af9e5 | |
parent | 429687d2ad47bc7093a45b6c62b8f29275a1eb48 (diff) |
Assume correct relative or absolute URL from Weblink provider
I you have a change URL like:
http://localhost:8080/c/test-project/+/688
Stepping back to parts "../../" will get you:
http://localhost:8080/c/
Wich is _not_ the base url.
Do not try to guess how URL is constructed but trust WebLink providers
to provide an absolute or a relative URL.
Provide correct relative url from Gitweb.
Bug: Issue 5316
Change-Id: I7f404d470a8fe0f32ef94bb2c7b4c6a9ba68a2b8
(cherry picked from commit 69ab4a8569a690da7d6fc0c57e0a74c2d97ef6c0)
3 files changed, 16 insertions, 7 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 6c0f7696b7..91eaf3c7d3 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 @@ -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"); } } } diff --git a/polygerrit-ui/app/elements/change/gr-commit-info/gr-commit-info.js b/polygerrit-ui/app/elements/change/gr-commit-info/gr-commit-info.js index 5aa8601dbb..6ccf7466f2 100644 --- a/polygerrit-ui/app/elements/change/gr-commit-info/gr-commit-info.js +++ b/polygerrit-ui/app/elements/change/gr-commit-info/gr-commit-info.js @@ -81,10 +81,6 @@ return; } - if (!/^https?\:\/\//.test(webLink)) { - webLink = '../../' + webLink; - } - return webLink; }, diff --git a/polygerrit-ui/app/elements/change/gr-commit-info/gr-commit-info_test.html b/polygerrit-ui/app/elements/change/gr-commit-info/gr-commit-info_test.html index c8faff5d64..10a51f619c 100644 --- a/polygerrit-ui/app/elements/change/gr-commit-info/gr-commit-info_test.html +++ b/polygerrit-ui/app/elements/change/gr-commit-info/gr-commit-info_test.html @@ -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() { |