Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-16368]
HyperlinkNote shouldn't emit the absolute URL.
  • Loading branch information
kohsuke committed Mar 1, 2013
1 parent 00bfa35 commit 9447289
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -64,6 +64,9 @@
<li class=bug>
Fixed "Manage" sub-contextmenu for non-standalone deployments
(<a href="https://github.com/jenkinsci/jenkins/pull/721">pull 721</a>)
<li class=bug>
Absolute URLs in console output
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-16368">issue 16368</a>)
<li class=bug>
Revert ampersand encoding which can cause backwad incompatibility issue
(<a href="https://github.com/jenkinsci/jenkins/pull/683">pull 683</a>)
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/hudson/Functions.java
Expand Up @@ -183,6 +183,8 @@ public static void initPageVariables(JellyContext context) {
the same thing as "/abc/def.ghi", but this avoids the stale cache
problem when the user upgrades to new Jenkins. Stapler also sets a long
future expiration dates for such static resources.
see https://wiki.jenkins-ci.org/display/JENKINS/Hyperlinks+in+HTML
*/
context.setVariable("resURL",rootURL+getResourcePath());
context.setVariable("imagesURL",rootURL+getResourcePath()+"/images");
Expand Down
14 changes: 12 additions & 2 deletions core/src/main/java/hudson/console/HyperlinkNote.java
Expand Up @@ -26,6 +26,8 @@
import hudson.Extension;
import hudson.MarkupText;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;

import java.io.IOException;
import java.util.logging.Level;
Expand Down Expand Up @@ -53,8 +55,16 @@ public HyperlinkNote(String url, int length) {
@Override
public ConsoleAnnotator annotate(Object context, MarkupText text, int charPos) {
String url = this.url;
if (url.startsWith("/"))
url = Jenkins.getInstance().getRootUrl()+url.substring(1);
if (url.startsWith("/")) {
StaplerRequest req = Stapler.getCurrentRequest();
if (req!=null) {
// if we are serving HTTP request, we want to use app relative URL
url = req.getContextPath()+url;
} else {
// otherwise presumably this is rendered for e-mails and other non-HTTP stuff
url = Jenkins.getInstance().getRootUrl()+url.substring(1);
}
}
text.addMarkup(charPos, charPos + length, "<a href='" + url + "'"+extraAttributes()+">", "</a>");
return null;
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/jenkins/model/Jenkins.java
Expand Up @@ -1864,6 +1864,7 @@ public String getUrlChildPrefix() {
* @since 1.66
* @see Descriptor#getCheckUrl(String)
* @see #getRootUrlFromRequest()
* @see <a href="https://wiki.jenkins-ci.org/display/JENKINS/Hyperlinks+in+HTML">Hyperlinks in HTML</a>
*/
public String getRootUrl() {
String url = JenkinsLocationConfiguration.get().getUrl();
Expand Down

0 comments on commit 9447289

Please sign in to comment.