From 975ef0e9558d3a903eb399e37d26c4cd46625c10 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 23 Oct 2012 10:38:21 +0200 Subject: [PATCH] SONAR-3903 Error when a duplication is detected on a filename containing XML entities like ampersand --- .../java/org/sonar/plugins/cpd/SonarEngine.java | 3 ++- .../org/sonar/plugins/cpd/SonarEngineTest.java | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java index 88c2c90656a..7187746e5ad 100644 --- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java +++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java @@ -21,6 +21,7 @@ package org.sonar.plugins.cpd; import com.google.common.collect.Iterables; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringEscapeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.SensorContext; @@ -210,7 +211,7 @@ public class SonarEngine extends CpdEngine { for (ClonePart part : duplication.getCloneParts()) { xml.append(""); } xml.append(""); diff --git a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/SonarEngineTest.java b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/SonarEngineTest.java index 434049fdbd6..c5511962b37 100644 --- a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/SonarEngineTest.java +++ b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/SonarEngineTest.java @@ -23,6 +23,7 @@ import org.junit.Before; import org.junit.Test; import org.sonar.api.batch.SensorContext; import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.resources.File; import org.sonar.api.resources.JavaFile; import org.sonar.api.resources.Resource; import org.sonar.api.test.IsMeasure; @@ -129,6 +130,22 @@ public class SonarEngineTest { + ""))); } + @Test + public void shouldEscapeXmlEntities() { + File csharpFile = new File("Loads/File Loads/Subs & Reds/SubsRedsDelivery.cs"); + List groups = Arrays.asList(newCloneGroup( + new ClonePart("Loads/File Loads/Subs & Reds/SubsRedsDelivery.cs", 0, 5, 204), + new ClonePart("Loads/File Loads/Subs & Reds/SubsRedsDelivery2.cs", 0, 15, 214))); + SonarEngine.save(context, csharpFile, groups); + + verify(context).saveMeasure( + eq(csharpFile), + argThat(new IsMeasure(CoreMetrics.DUPLICATIONS_DATA, "" + + "" + + "" + + ""))); + } + private CloneGroup newCloneGroup(ClonePart... parts) { return CloneGroup.builder().setLength(0).setOrigin(parts[0]).setParts(Arrays.asList(parts)).build(); } -- 2.39.5