Skip to content

Commit

Permalink
[FIXED JENKINS-44987] Push section names through markup formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergondza committed Aug 17, 2017
1 parent 086f0f9 commit 8524de2
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 9 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Expand Up @@ -72,6 +72,13 @@
<version>1.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>antisamy-markup-formatter</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
Expand Up @@ -48,6 +48,8 @@
import jenkins.model.Jenkins;
import org.kohsuke.stapler.Stapler;

import javax.annotation.Nonnull;

public abstract class SectionedViewSection implements ExtensionPoint, Describable<SectionedViewSection> {

public SectionedViewSection(String name, Width width, Positioning alignment) {
Expand Down Expand Up @@ -89,8 +91,8 @@ public static DescriptorExtensionList<SectionedViewSection, SectionedViewSection
return Hudson.getInstance().<SectionedViewSection, SectionedViewSectionDescriptor>getDescriptorList(SectionedViewSection.class);
}

public String getName() {
return name;
public @Nonnull String getName() {
return name == null ? "" : name;
}

public void setName(String name) {
Expand Down
Expand Up @@ -25,7 +25,7 @@ THE SOFTWARE.
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:sv="/lib/sectioned_view" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<j:if test="${section.name.length() > 0}">
<h2>${section.name}</h2>
<h2><j:out value="${app.markupFormatter.translate(section.name)}"/></h2>
</j:if>
<j:set var="sectionItems" value="${section.getItems(it.ownerItemGroup)}"/>
<j:if test="${empty(sectionItems)}">
Expand Down
Expand Up @@ -25,7 +25,7 @@ THE SOFTWARE.
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<j:if test="${section.name.length() > 0}">
<h2>${section.name}</h2>
<h2><j:out value="${app.markupFormatter.translate(section.name)}"/></h2>
</j:if>
<j:set var="sectionItems" value="${section.getItems(it.ownerItemGroup)}"/>
<j:if test="${empty(sectionItems)}">
Expand Down
Expand Up @@ -25,7 +25,7 @@ THE SOFTWARE.
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:sv="/lib/sectioned_view" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<j:if test="${section.name.length() > 0}">
<h2>${section.name}</h2>
<h2><j:out value="${app.markupFormatter.translate(section.name)}"/></h2>
</j:if>
<j:set var="sectionItems" value="${section.getItems(it.ownerItemGroup)}"/>
<j:if test="${empty(sectionItems)}">
Expand Down
Expand Up @@ -24,18 +24,18 @@ THE SOFTWARE.
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<j:if test="${section.name.length() > 0 and !section.hasStyle()}">
<h2>${section.name}</h2>
<h2><j:out value="${app.markupFormatter.translate(section.name)}"/></h2>
</j:if>
<table style="border: none; margin: 0; padding: 0;">
<tr>
<td>
<div class="${section.style.cssClass}">
<j:if test="${section.name.length() > 0 and section.hasStyle()}">
<h3>${section.name}</h3>
<h3><j:out value="${app.markupFormatter.translate(section.name)}"/></h3>
</j:if>
<div style="white-space: normal"><j:out value="${app.markupFormatter.translate(section.text)}"/></div>
</div>
</td>
</tr>
</table>
</j:jelly>
</j:jelly>
Expand Up @@ -37,7 +37,7 @@ THE SOFTWARE.
</d:taglib>

<j:if test="${section.name.length() > 0}">
<h2>${section.name}</h2>
<h2><j:out value="${app.markupFormatter.translate(section.name)}"/></h2>
</j:if>
<div>
<table>
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/hudson/plugins/sectioned_view/SectionedViewTest.java
Expand Up @@ -8,6 +8,7 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import hudson.markup.RawHtmlMarkupFormatter;
import hudson.model.Descriptor;
import hudson.model.ItemGroup;
import hudson.util.DescribableList;
Expand Down Expand Up @@ -56,5 +57,21 @@ public void doNotEnumerateItemsRepeatedly() throws Exception {
verify(lvs, times(1)).getItems(any(ItemGroup.class));
verify(trvs, times(1)).getItems(any(ItemGroup.class));
}

@Test @Issue("JENKINS-44987")
public void htmlUI() throws Exception {
String MARKUP = "<div><b><a href=\"adsf\">LVS</a></b></div>";

j.jenkins.setMarkupFormatter(new RawHtmlMarkupFormatter(false));

SectionedView sw = new SectionedView("SW");
j.jenkins.addView(sw);
DescribableList<SectionedViewSection, Descriptor<SectionedViewSection>> sections = (DescribableList<SectionedViewSection, Descriptor<SectionedViewSection>>) sw.getSections();
sections.add(new ListViewSection(MARKUP, SectionedViewSection.Width.THIRD, SectionedViewSection.Positioning.CENTER));

JenkinsRule.WebClient wc = j.createWebClient();
String content = wc.getPage(sw).getWebResponse().getContentAsString();
assertThat(content, containsString(MARKUP));
}
}

0 comments on commit 8524de2

Please sign in to comment.