aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlCodeBuilder.java5
-rw-r--r--sonar-colorizer/src/main/resources/sonar-colorizer.css8
-rw-r--r--sonar-colorizer/src/test/java/org/sonar/colorizer/CodeColorizerTest.java29
-rw-r--r--sonar-server/src/main/webapp/javascripts/resource.js2
4 files changed, 33 insertions, 11 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 &lt;b&gt;something&lt;/b&gt;</span></pre>",
+ "<pre><span class=\"cppd\"> *</span></pre>",
+ "<pre><span class=\"cppd\"> * &amp;lt;p&amp;gt;description&amp;lt;/p&amp;gt;</span></pre>",
+ "<pre><span class=\"cppd\"> */</span></pre>");
+ }
+
/**
* @return Reader for specified file with EOL normalized to specified one.
*/
diff --git a/sonar-server/src/main/webapp/javascripts/resource.js b/sonar-server/src/main/webapp/javascripts/resource.js
index 8c1dcc8179b..97318979a8d 100644
--- a/sonar-server/src/main/webapp/javascripts/resource.js
+++ b/sonar-server/src/main/webapp/javascripts/resource.js
@@ -206,5 +206,5 @@ function collapseTests(index, elt){
function highlight_usages(event){
var selectedClass = $j(this).attr("class").split(" ")[0];
$j("#" + event.data.id + " span.highlighted").removeClass("highlighted");
- $j("#" + event.data.id + " span." + selectedClass).toggleClass("highlighted");
+ $j("#" + event.data.id + " span." + selectedClass).addClass("highlighted");
} \ No newline at end of file