diff options
author | Jean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com> | 2013-04-23 16:37:23 +0200 |
---|---|---|
committer | Jean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com> | 2013-04-23 16:37:23 +0200 |
commit | 3fadbde9fc4c1b6000f8e592b07cc3bbc3d8319e (patch) | |
tree | b494c682f1001c7c87c9bf875f487fa9f3083438 /sonar-colorizer/src | |
parent | cad8a44428531aa4a8bf7962381e1a6c9464c06d (diff) | |
download | sonarqube-3fadbde9fc4c1b6000f8e592b07cc3bbc3d8319e.tar.gz sonarqube-3fadbde9fc4c1b6000f8e592b07cc3bbc3d8319e.zip |
SONAR-4258 Added ampersand escaping in sonar-colorizer
Diffstat (limited to 'sonar-colorizer/src')
3 files changed, 32 insertions, 10 deletions
diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlCodeBuilder.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlCodeBuilder.java index 8b536378a34..6c99ca65fd4 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlCodeBuilder.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlCodeBuilder.java @@ -39,7 +39,10 @@ public class HtmlCodeBuilder implements Appendable { colorizedCode.append("<"); } else if (c == '>') { colorizedCode.append(">"); - } else { + } else if (c == '&') { + colorizedCode.append("&"); + } + else { colorizedCode.append(c); } return this; diff --git a/sonar-colorizer/src/main/resources/sonar-colorizer.css b/sonar-colorizer/src/main/resources/sonar-colorizer.css index 38f4f67afc5..33813f45051 100644 --- a/sonar-colorizer/src/main/resources/sonar-colorizer.css +++ b/sonar-colorizer/src/main/resources/sonar-colorizer.css @@ -65,11 +65,15 @@ } .highlightable { - text-decoration: underline; - color: #0000AA; + /*text-decoration: underline;*/ + /*color: #0000AA;*/ cursor: hand; cursor: pointer; } +.highlightable:hover { + background-color: #ff8c00; +} + .highlighted { background-color: yellow; } diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/CodeColorizerTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/CodeColorizerTest.java index ae591b617d1..12a87f1887c 100644 --- a/sonar-colorizer/src/test/java/org/sonar/colorizer/CodeColorizerTest.java +++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/CodeColorizerTest.java @@ -19,13 +19,6 @@ */ package org.sonar.colorizer; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsNot.not; -import static org.hamcrest.number.OrderingComparisons.greaterThan; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - import org.apache.commons.io.IOUtils; import org.junit.Test; @@ -40,6 +33,13 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsNot.not; +import static org.hamcrest.number.OrderingComparisons.greaterThan; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + public class CodeColorizerTest { @Test @@ -122,6 +122,21 @@ public class CodeColorizerTest { } } + @Test + public void shouldEscapeSpecialCharacters() throws Exception { + + Reader java = readFile("/org/sonar/colorizer/samples/SampleWithComments.java"); + + String html = CodeColorizer.javaToHtml(java, HtmlOptions.DEFAULT); + + assertHtml(html); + assertContains(html, "<pre> <span class=\"cppd\">/*</span></pre>", + "<pre><span class=\"cppd\"> * This method does <b>something</b></span></pre>", + "<pre><span class=\"cppd\"> *</span></pre>", + "<pre><span class=\"cppd\"> * &lt;p&gt;description&lt;/p&gt;</span></pre>", + "<pre><span class=\"cppd\"> */</span></pre>"); + } + /** * @return Reader for specified file with EOL normalized to specified one. */ |