<?xml version="1.0" encoding="UTF-8"?>

<ruleset name="Error Prone"
         xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">

    <description>
Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
    </description>

    <rule name="MistypedCDATASection"
          language="xml"
          since="5.0"
          message="Potentially mistyped CDATA section with extra [ at beginning or ] at the end."
          class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_xml_errorprone.html#mistypedcdatasection">
        <description>
An XML CDATA section begins with a &lt;![CDATA[ marker, which has only one [, and ends with a ]]&gt; marker, which has two ].
        </description>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value>
<![CDATA[
//cdata-section[starts-with(@Text,'[') or ends-with(@Text,']')]
]]>
                </value>
            </property>
        </properties>
        <example>
<![CDATA[
<root>
    <child>
        <![CDATA[[ character data ]]><![CDATA[]]]]><![CDATA[> - this cdata section is valid, but it contains an
        additional square bracket at the beginning.
        It should probably be just <![CDATA[ character data ]]><![CDATA[]]]]><![CDATA[>.
    </child>
    <child>
        <![CDATA[ character data ]]]><![CDATA[]]]]><![CDATA[> - this cdata section is valid, but it contains an
        additional square bracket in the end.
        It should probably be just <![CDATA[ character data ]]><![CDATA[]]]]><![CDATA[>.
    </child>
</root>
]]>
        </example>
    </rule>

</ruleset>
