Skip to content

Commit

Permalink
Bugfix: #93 html tags not escaped on gitlab pull request decoration.
Browse files Browse the repository at this point in the history
Added htmlEscaping to Textformatter and removed whitespace and begin and end for the text.
  • Loading branch information
TeunoQuintor committed Aug 3, 2020
1 parent 79f6c5a commit 1ab6ba5
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 1ab6ba5

Please sign in to comment.