From 8de613644ce12346b59e28de4122b26dd7bf58a7 Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Fri, 29 Aug 2003 18:57:38 +0000 Subject: [PATCH] Fixed bug 797243 - CPD XML report can no longer contain ]]> (CDEnd) git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2230 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 1 + .../net/sourceforge/pmd/util/StringUtilTest.java | 4 ++++ pmd/src/net/sourceforge/pmd/cpd/XMLRenderer.java | 3 ++- pmd/src/net/sourceforge/pmd/util/StringUtil.java | 14 ++++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 7dc4bb0070..ec628354e8 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -3,6 +3,7 @@ Fixed bug 782246 - FinalFieldCouldBeStatic no longer flags fields in interfaces. Fixed bug 782235 - "ant -version" now prints more details when a file errors out. Fixed bug 779874 - LooseCouplingRule no longer triggers on ArrayList Fixed bug 781393 - VariableNameDeclaration no longer throws ClassCastExpression since ASTLocalVariableDeclaration now subclasses AccessNode +Fixed bug 797243 - CPD XML report can no longer contain ]]> (CDEnd) Fixed bug - Specifying a non-existing rule format on the command line no longer results in a ClassNotFoundException. XPath rules may now include pluggable parameters. This feature is very limited. For now. Tweaked CPD time display field diff --git a/pmd/regress/test/net/sourceforge/pmd/util/StringUtilTest.java b/pmd/regress/test/net/sourceforge/pmd/util/StringUtilTest.java index b941ce3b1c..749e2f3506 100644 --- a/pmd/regress/test/net/sourceforge/pmd/util/StringUtilTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/util/StringUtilTest.java @@ -13,4 +13,8 @@ public class StringUtilTest extends TestCase { assertEquals("faaaa", StringUtil.replaceString("foo", 'o', "aa")); } + public void testReplaceStringWithString() { + assertEquals("foo]]>bar", StringUtil.replaceString("foo]]>bar", "]]>", "]]>")); + } + } diff --git a/pmd/src/net/sourceforge/pmd/cpd/XMLRenderer.java b/pmd/src/net/sourceforge/pmd/cpd/XMLRenderer.java index 0130c75c7d..b283663b3f 100644 --- a/pmd/src/net/sourceforge/pmd/cpd/XMLRenderer.java +++ b/pmd/src/net/sourceforge/pmd/cpd/XMLRenderer.java @@ -1,6 +1,7 @@ package net.sourceforge.pmd.cpd; import net.sourceforge.pmd.PMD; +import net.sourceforge.pmd.util.StringUtil; import java.util.Iterator; @@ -44,6 +45,6 @@ public class XMLRenderer implements Renderer buffer.append(""); } buffer.append(""); - return buffer.toString(); + return StringUtil.replaceString(buffer.toString(), "]]>", "]]>"); } } diff --git a/pmd/src/net/sourceforge/pmd/util/StringUtil.java b/pmd/src/net/sourceforge/pmd/util/StringUtil.java index bb8f5ae27e..d382fa7121 100644 --- a/pmd/src/net/sourceforge/pmd/util/StringUtil.java +++ b/pmd/src/net/sourceforge/pmd/util/StringUtil.java @@ -16,4 +16,18 @@ public class StringUtil { return desc.toString(); } + public static String replaceString(String inputString, String oldString, String newString) { + StringBuffer desc = new StringBuffer(); + int index = inputString.indexOf(oldString); + int last = 0; + while (index != -1) { + desc.append(inputString.substring(last, index)); + desc.append(newString); + last = index + oldString.length(); + index = inputString.indexOf(oldString, last); + } + desc.append(inputString.substring(last)); + return desc.toString(); + } + }