Skip to content

Commit

Permalink
Added htmlEscaping to Textformatter and removed whitespace and begin …
Browse files Browse the repository at this point in the history
…and end for the text
  • Loading branch information
TeunoQuintor committed Jul 9, 2020
1 parent f925fb7 commit f35767e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.github.mc1arke.sonarqube.plugin.ce.pullrequest.markup;

import java.util.stream.IntStream;
import static com.google.common.html.HtmlEscapers.htmlEscaper;

public final class MarkdownFormatterFactory implements FormatterFactory {

Expand Down Expand Up @@ -110,7 +111,7 @@ public Formatter<Text> textFormatter() {
return new BaseFormatter<Text>() {
@Override
public String format(Text node, FormatterFactory formatterFactory) {
return node.getContent();
return htmlEscaper().escape(node.getContent()).trim();
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,18 @@ public void testTextFormatter() {
MarkdownFormatterFactory testCase = new MarkdownFormatterFactory();
assertEquals("Text", testCase.textFormatter().format(new Text("Text"), testCase));
}
}

@Test
public void testContentTextFormatterEscapedHtml(){
MarkdownFormatterFactory testCase = new MarkdownFormatterFactory();
assertEquals("&lt;p&gt; no html allowed", testCase.textFormatter().format(new Text("<p> no html allowed"), testCase));
assertEquals("no html &lt;p&gt; allowed", testCase.textFormatter().format(new Text("no html <p> allowed"), testCase));
assertEquals("&lt;/i&gt;no html &lt;p&gt; allowed&lt;i&gt;", testCase.textFormatter().format(new Text("</i>no html <p> allowed<i>"), testCase));
}

@Test
public void testContentTextFormatterTrimWhitespaceAtBeginAndEnd(){
MarkdownFormatterFactory testCase = new MarkdownFormatterFactory();
assertEquals("", testCase.textFormatter().format(new Text(" "), testCase));
}
}

0 comments on commit f35767e

Please sign in to comment.