Add MistypeCDATASection Rule to detect potential extra [ or ].
This is not in dogfood, as PMD does a lot of CDATASections which are the end of XPath steps, and this last character is a ]. We could reformat to work around the check (add a newline before the ]]>), but it seems a bit kludgy. git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@6548 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
1 parent
7534aedf0c
commit
7b4f809b41
5 files changed
+135
-8
No files matched your search
@@ -56,13 +56,7 @@ TODO - Release blockers - Must implement before this release can be finished
|
||||
for the new XML language.
|
||||
o Rework RuleReference to be done via Rule.isReference() instead of instanceof RuleReference?
|
||||
o Do something with ExternalRuleID, this should be inner class of RuleSetFactory?
|
||||
o Rule properties need to be cleaned up. We have the descriptor approach, and
|
||||
the simple named (but not type safe) approach. The descriptor approach
|
||||
should be the required approach. If we need runtime definition of properties
|
||||
(e.g. XML only), perhaps we need to make it explicit in the XML markup via
|
||||
a <property-descriptor> elements (wrapper around PropertyDescriptor interface),
|
||||
versus <property> element which should _only_ assign a non-default value to
|
||||
a property? Further, Rule documentation should be automatically generated
|
||||
o Rule documentation should be automatically generated
|
||||
from the descriptors, be they defined in code or XML, I think the code based
|
||||
descriptors are not getting seen.
|
||||
o Enhance Rule Designer to allow testing of the violation suppress Regex and XPath.
|
||||
@@ -405,7 +399,7 @@ Fixed ClassCastException on generic method in BeanMembersShouldSerialize
|
||||
Fixed ClassCastException in symbol table code
|
||||
retroweaver updated to version 2.0.6.
|
||||
|
||||
New rules:
|
||||
New Java rules:
|
||||
|
||||
Coupling ruleset: LoosePackageCoupling
|
||||
Controversial ruleset: AvoidPrefixingMethodParameters
|
||||
@@ -414,6 +408,9 @@ New rules:
|
||||
Basic ruleset: EmptyInitializer,EmptyStatementBlock,ExtendsObject,UselessParentheses,CheckSkipResult
|
||||
Design ruleset: LogicInversion,UseVarargs
|
||||
|
||||
New XML rules:
|
||||
Basic ruleset: MistypedCDATASection
|
||||
|
||||
March 25, 2008 - 4.2:
|
||||
|
||||
Fixed bug 1920155 - CheckResultSet: Does not pass for loop conditionals
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package test.net.sourceforge.pmd.lang.xml.rule.basic;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||
|
||||
public class BasicRulesTest extends SimpleAggregatorTst {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
addRule("xml-basic", "MistypedCDATASection");
|
||||
}
|
||||
|
||||
public static junit.framework.Test suite() {
|
||||
return new junit.framework.JUnit4TestAdapter(BasicRulesTest.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<test-data>
|
||||
<test-code>
|
||||
<description>No CDATASection</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
<root>
|
||||
<child>
|
||||
</child>
|
||||
</root>
|
||||
]]></code>
|
||||
<source-type>xml</source-type>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>Valid CDATASection</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
<root>
|
||||
<child>
|
||||
<![CDATA[
|
||||
some text data
|
||||
]]><![CDATA[]]]]><![CDATA[>]]><![CDATA[
|
||||
</child>
|
||||
</root>
|
||||
]]></code>
|
||||
<source-type>xml</source-type>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>CDATASection with [ and ] in it, but not at the ends</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
<root>
|
||||
<child>
|
||||
<![CDATA[
|
||||
some [text] data
|
||||
]]><![CDATA[]]]]><![CDATA[>]]><![CDATA[
|
||||
</child>
|
||||
</root>
|
||||
]]></code>
|
||||
<source-type>xml</source-type>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>CDATASection with [ at the beginning</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
<root>
|
||||
<child>
|
||||
<![CDATA[[
|
||||
some text data
|
||||
]]><![CDATA[]]]]><![CDATA[>]]><![CDATA[
|
||||
</child>
|
||||
</root>
|
||||
]]></code>
|
||||
<source-type>xml</source-type>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>CDATASection with ] at the end</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
<root>
|
||||
<child>
|
||||
<![CDATA[
|
||||
some text data
|
||||
]]]><![CDATA[]]]]><![CDATA[>]]><![CDATA[
|
||||
</child>
|
||||
</root>
|
||||
]]></code>
|
||||
<source-type>xml</source-type>
|
||||
</test-code>
|
||||
</test-data>
|
||||
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="Basic XML Rules"
|
||||
xmlns="http://pmd.sf.net/ruleset/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
|
||||
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
|
||||
<description>
|
||||
The Basic XML Ruleset contains a collection of good practices which everyone should follow.
|
||||
</description>
|
||||
|
||||
<rule name="MistypedCDATASection"
|
||||
language="xml"
|
||||
since="5.0"
|
||||
message="Potentialy mistyped CDATA section with extra [ at beginning or ] at the end."
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="http://pmd.sourceforge.net/rules/xml/basic.html#MistypedCDATASection">
|
||||
<description>
|
||||
An XML CDATA section begins with a <!CDATA[ marker, which has only one [, and ends with a ]]> marker, which has only two ].
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="version" value="2.0" />
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//cdata-section[starts-with(@Image,'[') or ends-with(@Image,']')]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
An extra [ looks like <!CDATA[[]]>, and an extra ] looks like <!CDATA[]]]>.
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
</ruleset>
|
||||
@@ -42,6 +42,7 @@ public class SimpleRuleSetNameMapper {
|
||||
}
|
||||
|
||||
private void populateNameMap() {
|
||||
// TODO Can these non-Language suffixed short names still continue? Would "java-basic" be more appropriate?
|
||||
nameMap.put("basic", "rulesets/basic.xml");
|
||||
nameMap.put("jsp", "rulesets/basic-jsp.xml");
|
||||
nameMap.put("jsf", "rulesets/basic-jsf.xml");
|
||||
@@ -70,6 +71,7 @@ public class SimpleRuleSetNameMapper {
|
||||
nameMap.put("typeresolution", "rulesets/typeresolution.xml");
|
||||
nameMap.put("unusedcode", "rulesets/unusedcode.xml");
|
||||
nameMap.put("useless", "rulesets/useless.xml");
|
||||
nameMap.put("xml-basic", "rulesets/xml/basic.xml");
|
||||
nameMap.put("33", "rulesets/releases/33.xml");
|
||||
nameMap.put("34", "rulesets/releases/34.xml");
|
||||
nameMap.put("35", "rulesets/releases/35.xml");
|
||||
|
||||
Reference in new issue
Block a user