mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-176558 Problem validating XML document
adding support for jdk.xml.maxOccurLimit property
This commit is contained in:
@@ -67,6 +67,7 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.xml.XmlAttributeDescriptor;
|
||||
import com.intellij.xml.XmlBundle;
|
||||
import com.intellij.xml.XmlElementDescriptor;
|
||||
import com.intellij.xml.actions.validate.ValidateXmlActionHandler;
|
||||
import com.intellij.xml.impl.schema.XmlElementDescriptorImpl;
|
||||
import com.intellij.xml.util.*;
|
||||
import gnu.trove.THashSet;
|
||||
@@ -2108,6 +2109,15 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase {
|
||||
doDoTest(true, false);
|
||||
}
|
||||
|
||||
public void testMaxOccurLimitValidation() throws Exception {
|
||||
configureByFiles(null, BASE_PATH + "MaxOccurLimit.xml", BASE_PATH + "MaxOccurLimit.xsd");
|
||||
assertTrue(doHighlighting().stream().anyMatch(info -> info.getSeverity() == HighlightSeverity.ERROR));
|
||||
|
||||
configureByFiles(null, BASE_PATH + "MaxOccurLimit.xml", BASE_PATH + "MaxOccurLimit.xsd");
|
||||
System.setProperty(ValidateXmlActionHandler.JDK_XML_MAX_OCCUR_LIMIT, "10000");
|
||||
assertFalse(doHighlighting().stream().anyMatch(info -> info.getSeverity() == HighlightSeverity.ERROR));
|
||||
}
|
||||
|
||||
public void testTheSameElement() throws Exception {
|
||||
doTest(
|
||||
new VirtualFile[] {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<procedure xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="MaxOccurLimit.xsd">
|
||||
<parameter name="caaxtgt">
|
||||
<string>
|
||||
<processingType>TYPE1</processingType>
|
||||
</string>
|
||||
</parameter>
|
||||
</procedure>
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<xs:element name="procedure">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="parameter" type="parameterType" minOccurs="0" maxOccurs="1300"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:complexType name="parameterType">
|
||||
<xs:sequence>
|
||||
<xs:choice>
|
||||
<xs:element name="string" type="strVarType">
|
||||
</xs:element>
|
||||
</xs:choice>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="name" type="xs:string" use="required"/>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="strVarType">
|
||||
<xs:sequence>
|
||||
<xs:choice>
|
||||
<xs:sequence minOccurs="0">
|
||||
<xs:element name="processingType" minOccurs="0">
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="TYPE1"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:choice>
|
||||
<xs:element name="choice" type="xs:string" minOccurs="0" maxOccurs="1300"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:schema>
|
||||
+14
-1
@@ -32,11 +32,15 @@ import org.apache.xerces.impl.XMLEntityManager;
|
||||
import org.apache.xerces.impl.XercesAccessor;
|
||||
import org.apache.xerces.jaxp.JAXPConstants;
|
||||
import org.apache.xerces.jaxp.SAXParserFactoryImpl;
|
||||
import org.apache.xerces.util.SecurityManager;
|
||||
import org.apache.xerces.util.XMLGrammarPoolImpl;
|
||||
import org.apache.xerces.xni.grammars.XMLGrammarPool;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.xml.sax.*;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXNotRecognizedException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
@@ -47,6 +51,8 @@ import java.io.StringReader;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.sun.org.apache.xerces.internal.impl.Constants.SECURITY_MANAGER;
|
||||
|
||||
/**
|
||||
* @author Mike
|
||||
*/
|
||||
@@ -62,6 +68,7 @@ public class ValidateXmlActionHandler {
|
||||
private static final Key<VirtualFile[]> DEPENDENT_FILES_KEY = Key.create("GrammarPoolFilesKey");
|
||||
private static final Key<String[]> KNOWN_NAMESPACES_KEY = Key.create("KnownNamespacesKey");
|
||||
private static final Key<Map<String, XMLEntityManager.Entity>> ENTITIES_KEY = Key.create("EntityManagerKey");
|
||||
public static final String JDK_XML_MAX_OCCUR_LIMIT = "jdk.xml.maxOccurLimit";
|
||||
|
||||
private Project myProject;
|
||||
private XmlFile myFile;
|
||||
@@ -240,6 +247,12 @@ public class ValidateXmlActionHandler {
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
|
||||
String property = System.getProperty(JDK_XML_MAX_OCCUR_LIMIT);
|
||||
if (property != null) {
|
||||
SecurityManager securityManager = (SecurityManager)parser.getProperty(SECURITY_MANAGER);
|
||||
securityManager.setMaxOccurNodeLimit(Integer.parseInt(property));
|
||||
}
|
||||
|
||||
if (schemaChecking) { // when dtd checking schema refs could not be validated @see http://marc.theaimsgroup.com/?l=xerces-j-user&m=112504202423704&w=2
|
||||
XMLGrammarPool grammarPool = getGrammarPool(myFile, myForceChecking);
|
||||
configureEntityManager(myFile, parser);
|
||||
|
||||
Reference in New Issue
Block a user