From ece6a68e4fc1c730b7b60825b370304aa491557b Mon Sep 17 00:00:00 2001 From: Ronald Holshausen Date: Mon, 11 Dec 2023 15:19:08 +1100 Subject: [PATCH] chore: Remove xerces #1743 --- core/matchers/build.gradle | 1 - .../pact/core/matchers/XmlContentMatcher.kt | 21 +++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/core/matchers/build.gradle b/core/matchers/build.gradle index 85c9f31df..de89f4587 100644 --- a/core/matchers/build.gradle +++ b/core/matchers/build.gradle @@ -17,7 +17,6 @@ dependencies { implementation 'javax.mail:mail:1.5.0-b01' implementation 'org.apache.tika:tika-core' implementation 'io.github.java-diff-utils:java-diff-utils:4.12' - implementation 'xerces:xercesImpl:2.12.2' implementation 'org.atteo:evo-inflector:1.3' implementation 'com.github.ajalt:mordant:1.2.1' implementation 'com.github.zafarkhaja:java-semver:0.9.0' diff --git a/core/matchers/src/main/kotlin/au/com/dius/pact/core/matchers/XmlContentMatcher.kt b/core/matchers/src/main/kotlin/au/com/dius/pact/core/matchers/XmlContentMatcher.kt index 5a3d432f2..dde42f57a 100755 --- a/core/matchers/src/main/kotlin/au/com/dius/pact/core/matchers/XmlContentMatcher.kt +++ b/core/matchers/src/main/kotlin/au/com/dius/pact/core/matchers/XmlContentMatcher.kt @@ -6,7 +6,6 @@ import au.com.dius.pact.core.support.Result import au.com.dius.pact.core.support.zipAll import io.pact.plugins.jvm.core.InteractionContents import io.github.oshai.kotlinlogging.KLogging -import org.apache.xerces.dom.TextImpl import org.w3c.dom.NamedNodeMap import org.w3c.dom.Node import org.w3c.dom.Node.CDATA_SECTION_NODE @@ -52,18 +51,18 @@ object XmlContentMatcher : ContentMatcher, KLogging() { } fun parse(xmlData: String): Node { + val dbFactory = DocumentBuilderFactory.newInstance() + if (System.getProperty("pact.matching.xml.validating") == "false") { + dbFactory.isValidating = false + dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false) + dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false) + } + if (System.getProperty("pact.matching.xml.namespace-aware") != "false") { + dbFactory.isNamespaceAware = true + } return if (xmlData.isEmpty()) { - TextImpl() + dbFactory.newDocumentBuilder().newDocument() } else { - val dbFactory = DocumentBuilderFactory.newInstance() - if (System.getProperty("pact.matching.xml.validating") == "false") { - dbFactory.isValidating = false - dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false) - dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false) - } - if (System.getProperty("pact.matching.xml.namespace-aware") != "false") { - dbFactory.isNamespaceAware = true - } val dBuilder = dbFactory.newDocumentBuilder() val xmlInput = InputSource(StringReader(xmlData)) val doc = dBuilder.parse(xmlInput)