aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Varghese2014-03-20 21:10:51 (EDT)
committerRoy Varghese2014-03-20 21:24:01 (EDT)
commit6e55eca01ce21ce71b89753f79c7d8fa718f6edb (patch)
tree02996880cb2b6be33a7528de2786169642f0e21b
parent5a4efbbdb736e15e673cd5b0f1b28803a42bfd4a (diff)
downloadorg.eclipse.hudson.core-6e55eca01ce21ce71b89753f79c7d8fa718f6edb.zip
org.eclipse.hudson.core-6e55eca01ce21ce71b89753f79c7d8fa718f6edb.tar.gz
org.eclipse.hudson.core-6e55eca01ce21ce71b89753f79c7d8fa718f6edb.tar.bz2
Fix 430314: Everything after host and port is ignored in a custom Hudson URLrefs/changes/91/23691/1
Signed-Off-by: Roy Varghese <rovarghe@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/model/Hudson.java45
1 files changed, 31 insertions, 14 deletions
diff --git a/hudson-core/src/main/java/hudson/model/Hudson.java b/hudson-core/src/main/java/hudson/model/Hudson.java
index bdfacfb..9ee90d5 100644
--- a/hudson-core/src/main/java/hudson/model/Hudson.java
+++ b/hudson-core/src/main/java/hudson/model/Hudson.java
@@ -200,6 +200,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.LogRecord;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.antlr.runtime.RecognitionException;
import org.eclipse.hudson.plugins.PluginCenter;
@@ -1908,20 +1909,36 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
public String getRootUrl() {
// for compatibility. the actual data is stored in Mailer
String url = Mailer.descriptor().getUrl();
- if (url != null) {
- URL theUrl;
- try {
- theUrl = new URL(url);
- } catch (MalformedURLException e) {
- return url;
- }
- // Fix 414064 If Hudson URL is configured, the port is ignored
- int port = theUrl.getPort();
- String thePort = port == 80 || port == -1 ? "" : ":" + port;
- String hostNamePart = theUrl.getProtocol() + "://"
- + theUrl.getHost() + thePort;
- return hostNamePart + Functions.getRequestRootPath() + '/';
- }
+ if (url != null) {
+ // Could be static.
+ Pattern slashTrimmer = Pattern.compile("/?(.*[^/])/?$");
+ // Trim leading and trailing slashes
+ String theRequestPath = Functions.getRequestRootPath();
+ theRequestPath = theRequestPath == null ? "" :theRequestPath;
+ Matcher matcher = slashTrimmer.matcher(theRequestPath);
+ theRequestPath = matcher.find() ? matcher.group(1): "";
+
+
+ try {
+ URL theUrl = new URL(url);
+ // Similar trim
+ String thePath = theUrl.getPath();
+ matcher.reset(thePath);
+ thePath = matcher.find() ? matcher.group(1) : "";
+
+ // Put them back together
+ URL rootUrl = new URL (theUrl.getProtocol(), theUrl.getHost(),
+ theUrl.getPort(), String.format("%s%s%s%s/",
+ thePath.isEmpty()? "": "/",
+ thePath,
+ theRequestPath.isEmpty()? "":"/",
+ theRequestPath));
+ return rootUrl.toString();
+ } catch (MalformedURLException e) {
+ return url;
+ }
+
+ }
StaplerRequest req = Stapler.getCurrentRequest();
if (req != null) {