From 73dfb85bc4ce8f75afc6fe4a7ce0552cd330c6e8 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Wed, 26 Jul 2017 12:57:25 +0300 Subject: [PATCH] IDEA-176558 Problem validating XML document adding support for jdk.xml.maxOccurLimit property --- .../daemon/XmlHighlightingTest.java | 10 +++++ xml/tests/testData/xml/MaxOccurLimit.xml | 9 +++++ xml/tests/testData/xml/MaxOccurLimit.xsd | 37 +++++++++++++++++++ .../validate/ValidateXmlActionHandler.java | 15 +++++++- 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 xml/tests/testData/xml/MaxOccurLimit.xml create mode 100644 xml/tests/testData/xml/MaxOccurLimit.xsd diff --git a/xml/tests/src/com/intellij/codeInsight/daemon/XmlHighlightingTest.java b/xml/tests/src/com/intellij/codeInsight/daemon/XmlHighlightingTest.java index 6140f8848fec..86e0ff63e1bf 100644 --- a/xml/tests/src/com/intellij/codeInsight/daemon/XmlHighlightingTest.java +++ b/xml/tests/src/com/intellij/codeInsight/daemon/XmlHighlightingTest.java @@ -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[] { diff --git a/xml/tests/testData/xml/MaxOccurLimit.xml b/xml/tests/testData/xml/MaxOccurLimit.xml new file mode 100644 index 000000000000..75946813de07 --- /dev/null +++ b/xml/tests/testData/xml/MaxOccurLimit.xml @@ -0,0 +1,9 @@ + + + + + TYPE1 + + + diff --git a/xml/tests/testData/xml/MaxOccurLimit.xsd b/xml/tests/testData/xml/MaxOccurLimit.xsd new file mode 100644 index 000000000000..efe8d1dccdae --- /dev/null +++ b/xml/tests/testData/xml/MaxOccurLimit.xsd @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xml/xml-psi-impl/src/com/intellij/xml/actions/validate/ValidateXmlActionHandler.java b/xml/xml-psi-impl/src/com/intellij/xml/actions/validate/ValidateXmlActionHandler.java index 0e98e6d82663..663d2817b4e4 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/actions/validate/ValidateXmlActionHandler.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/actions/validate/ValidateXmlActionHandler.java @@ -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 DEPENDENT_FILES_KEY = Key.create("GrammarPoolFilesKey"); private static final Key KNOWN_NAMESPACES_KEY = Key.create("KnownNamespacesKey"); private static final Key> 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);