Merge branch 'bug-1518' into pmd/5.5.x
This commit is contained in:
@ -52,8 +52,13 @@ public class SourceCodePositioner {
|
||||
}
|
||||
|
||||
public int columnFromOffset(int lineNumber, int offset) {
|
||||
int columnOffset = offset - lineOffsets[lineNumber - 1];
|
||||
return columnOffset + 1; // 1-based column offsets
|
||||
int lineIndex = lineNumber - 1;
|
||||
if (lineIndex < 0 || lineIndex >= lineOffsets.length) {
|
||||
// no line number found...
|
||||
return 0;
|
||||
}
|
||||
int columnOffset = offset - lineOffsets[lineNumber - 1];
|
||||
return columnOffset + 1; // 1-based column offsets
|
||||
}
|
||||
|
||||
public int getLastLine() {
|
||||
|
@ -34,21 +34,31 @@ class DOMLineNumbers {
|
||||
}
|
||||
private int determineLocation(Node n, int index) {
|
||||
int nextIndex = index;
|
||||
int nodeLength = 0;
|
||||
int textLength = 0;
|
||||
if (n.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
|
||||
nextIndex = xmlString.indexOf("<!DOCTYPE", nextIndex);
|
||||
nodeLength = "<!DOCTYPE".length();
|
||||
} else if (n.getNodeType() == Node.COMMENT_NODE) {
|
||||
nextIndex = xmlString.indexOf("<!--", nextIndex);
|
||||
} else if (n.getNodeType() == Node.ELEMENT_NODE) {
|
||||
nextIndex = xmlString.indexOf("<" + n.getNodeName(), nextIndex);
|
||||
nodeLength = xmlString.indexOf(">", nextIndex) - nextIndex + 1;
|
||||
} else if (n.getNodeType() == Node.CDATA_SECTION_NODE) {
|
||||
nextIndex = xmlString.indexOf("<![CDATA[", nextIndex);
|
||||
} else if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
|
||||
ProcessingInstruction pi = (ProcessingInstruction)n;
|
||||
nextIndex = xmlString.indexOf("<?" + pi.getTarget(), nextIndex);
|
||||
} else if (n.getNodeType() == Node.TEXT_NODE) {
|
||||
String te = unexpandEntities(n, n.getNodeValue());
|
||||
String te = unexpandEntities(n, n.getNodeValue(), true);
|
||||
int newIndex = xmlString.indexOf(te, nextIndex);
|
||||
if (newIndex == -1) {
|
||||
// try again without escaping the quotes
|
||||
te = unexpandEntities(n, n.getNodeValue(), false);
|
||||
newIndex = xmlString.indexOf(te, nextIndex);
|
||||
}
|
||||
if (newIndex > 0) {
|
||||
textLength = te.length();
|
||||
nextIndex = newIndex;
|
||||
}
|
||||
} else if (n.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
|
||||
@ -56,6 +66,8 @@ class DOMLineNumbers {
|
||||
}
|
||||
setBeginLocation(n, nextIndex);
|
||||
if (n.hasChildNodes()) {
|
||||
// next nodes begin after the current start tag
|
||||
nextIndex += nodeLength;
|
||||
NodeList childs = n.getChildNodes();
|
||||
for (int i = 0; i < childs.getLength(); i++) {
|
||||
nextIndex = determineLocation(childs.item(i), nextIndex);
|
||||
@ -76,8 +88,7 @@ class DOMLineNumbers {
|
||||
nextIndex += 4 + 3; // <!-- and -->
|
||||
nextIndex += n.getNodeValue().length();
|
||||
} else if (n.getNodeType() == Node.TEXT_NODE) {
|
||||
String te = unexpandEntities(n, n.getNodeValue());
|
||||
nextIndex += te.length();
|
||||
nextIndex += textLength;
|
||||
} else if (n.getNodeType() == Node.CDATA_SECTION_NODE) {
|
||||
nextIndex += "<![CDATA[".length() + n.getNodeValue().length() + "]]>".length();
|
||||
} else if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
|
||||
@ -88,15 +99,17 @@ class DOMLineNumbers {
|
||||
return nextIndex;
|
||||
}
|
||||
|
||||
private String unexpandEntities(Node n, String te) {
|
||||
private String unexpandEntities(Node n, String te, boolean withQuotes) {
|
||||
String result = te;
|
||||
DocumentType doctype = n.getOwnerDocument().getDoctype();
|
||||
// implicit entities
|
||||
result = result.replaceAll(Matcher.quoteReplacement("&"), "&");
|
||||
result = result.replaceAll(Matcher.quoteReplacement("<"), "<");
|
||||
result = result.replaceAll(Matcher.quoteReplacement(">"), ">");
|
||||
result = result.replaceAll(Matcher.quoteReplacement("\""), """);
|
||||
result = result.replaceAll(Matcher.quoteReplacement("'"), "'");
|
||||
if (withQuotes) {
|
||||
result = result.replaceAll(Matcher.quoteReplacement("\""), """);
|
||||
result = result.replaceAll(Matcher.quoteReplacement("'"), "'");
|
||||
}
|
||||
|
||||
if (doctype != null) {
|
||||
NamedNodeMap entities = doctype.getEntities();
|
||||
|
@ -3,6 +3,8 @@
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.xml;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.io.StringReader;
|
||||
@ -10,6 +12,10 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.Parser;
|
||||
@ -19,9 +25,6 @@ import net.sourceforge.pmd.lang.xml.ast.XmlNode;
|
||||
import net.sourceforge.pmd.lang.xml.ast.XmlParser;
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit test for the {@link XmlParser}.
|
||||
*/
|
||||
@ -369,6 +372,21 @@ public class XmlParserTest {
|
||||
assertLineNumbers(document.jjtGetChild(0), 1, 22, 1, 29);
|
||||
}
|
||||
|
||||
private Node parseXml(String xml) {
|
||||
LanguageVersionHandler xmlVersionHandler = LanguageRegistry.getLanguage(XmlLanguageModule.NAME).getDefaultVersion().getLanguageVersionHandler();
|
||||
XmlParserOptions options = (XmlParserOptions)xmlVersionHandler.getDefaultParserOptions();
|
||||
Parser parser = xmlVersionHandler.getParser(options);
|
||||
Node document = parser.parse(null, new StringReader(xml));
|
||||
return document;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug1518() throws Exception {
|
||||
String xml = IOUtils.toString(XmlParserTest.class.getResourceAsStream("parsertests/bug1518.xml"));
|
||||
Node document = parseXml(xml);
|
||||
assertNotNull(document);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts a single node inclusive attributes.
|
||||
* @param node the node
|
||||
|
@ -0,0 +1,26 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<deployment-plan xmlns="http://xmlns.oracle.com/weblogic/deployment-plan"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/deployment-plan http://xmlns.oracle.com/weblogic/deployment-plan/1.0/deployment-plan.xsd"
|
||||
global-variables="false">
|
||||
<application-name>app</application-name>
|
||||
<variable-definition>
|
||||
<variable>
|
||||
<name>Application_Module_Web_ContextRoot</name>
|
||||
<value xsi:nil="false">ikb.adf.kreda.abw.webapp-Abnahmetest-ohne-SSO</value>
|
||||
</variable>
|
||||
</variable-definition>
|
||||
<module-override>
|
||||
<module-name>ikb.adf.kreda.abw.ear</module-name>
|
||||
<module-type>ear</module-type>
|
||||
<module-descriptor external="false">
|
||||
<root-element>application</root-element>
|
||||
<uri>META-INF/application.xml</uri>
|
||||
<variable-assignment>
|
||||
<name>Application_Module_Web_ContextRoot</name>
|
||||
<xpath>/application/module/web/[context-root="ikb.adf.kreda.abw.webapp-Local-ohne-SSO"]</xpath>
|
||||
<operation>replace</operation>
|
||||
</variable-assignment>
|
||||
</module-descriptor>
|
||||
</module-override>
|
||||
</deployment-plan>
|
@ -15,9 +15,12 @@
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* apex-apexunit
|
||||
* [#1543](https://sourceforge.net/p/pmd/bugs/1543/): \[apex] ApexUnitTestClassShouldHaveAsserts assumes APEX is case sensitive
|
||||
* General
|
||||
* [#1542](https://sourceforge.net/p/pmd/bugs/1542/): \[java] CPD throws an NPE when parsing enums with -ignore-identifiers
|
||||
* apex-apexunit
|
||||
* [#1543](https://sourceforge.net/p/pmd/bugs/1543/): \[apex] ApexUnitTestClassShouldHaveAsserts assumes APEX is case sensitive
|
||||
* XML
|
||||
* [#1518](https://sourceforge.net/p/pmd/bugs/1518/): \[xml] Error while processing xml file with ".webapp" in the file or directory name
|
||||
|
||||
|
||||
**API Changes:**
|
||||
|
Reference in New Issue
Block a user