Skip to content
Permalink
Browse files
Merge pull request #64 from stephenc/jenkins-40827
[JENKINS-40827] Fix the escaping in description column
  • Loading branch information
stephenc committed Jan 6, 2017
2 parents d6f0e49 + 31d8b67 commit 1fe2a0d42df5c12470d574e21cdd6051c3256347
Showing with 16 additions and 5 deletions.
  1. +1 −1 pom.xml
  2. +15 −4 src/main/java/jenkins/branch/DescriptionColumn.java
@@ -66,7 +66,7 @@

<properties>
<jenkins.version>1.642.3</jenkins.version>
<scm-api.version>2.0.1-beta-1</scm-api.version>
<scm-api.version>2.0.1-20170105.113635-7</scm-api.version>
</properties>

<repositories>
@@ -27,11 +27,15 @@
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.Util;
import hudson.markup.MarkupFormatter;
import hudson.model.Actionable;
import hudson.model.Item;
import hudson.model.Job;
import hudson.views.ListViewColumn;
import hudson.views.ListViewColumnDescriptor;
import java.io.IOException;
import jenkins.model.Jenkins;
import jenkins.scm.api.metadata.ObjectMetadataAction;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.accmod.Restricted;
@@ -77,12 +81,19 @@ public ObjectMetadataAction getPropertyOf(Item item) {
*/
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // used via Jelly EL binding
public String description(@CheckForNull Object p, @NonNull Object job) {
public String description(@CheckForNull Object p, @NonNull Object job) throws IOException {
if (p instanceof ObjectMetadataAction) {
return StringUtils.defaultIfBlank(((ObjectMetadataAction) p).getObjectDescription(),
job instanceof Job ? ((Job) job).getDescription() : "");
// when the description comes from the metadata, assume plain text and use Util.escape
String description = Util.escape(((ObjectMetadataAction) p).getObjectDescription());
if (StringUtils.isNotBlank(description)) {
return description;
}
}
if (job instanceof Job) {
// when the description comes from the job configuration, assume user provided and use markup formatter
return Jenkins.getActiveInstance().getMarkupFormatter().translate(((Job) job).getDescription());
} else {
return job instanceof Job ? ((Job) job).getDescription() : "";
return "";
}
}

0 comments on commit 1fe2a0d

Please sign in to comment.