ITV / scala-pact

A Scala implementation of CDC using the Pact standard
Other
108 stars 54 forks source link

Issue with supporting XML requests which sends a DTD in the latest scala-xml version #237

Open danielbeddoe123 opened 1 year ago

danielbeddoe123 commented 1 year ago

The SAX parser created in scala-xml 2.1.0 has the following feature set to true by default:

parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true)

This has the consequence that when using this library and our client code sends an XML request with a DTD in it, MatchIr. fromXmlString which is used by BodyMatching.matchBodies fails to parse the XML properly and we end up with body match failures.

We would like some way of supplying a custom parser or supplying some configuration to toggle that feature, for e.g:

private val XML: XMLLoader[Elem] = createXMLParser(disallowDocType = false)
def createXMLParser(disallowDocType: Boolean = true): XMLLoader[Elem] = {
    val sAXParserFactory = SAXParserFactory.newInstance()
    sAXParserFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", disallowDocType);
    val saxParser = sAXParserFactory.newSAXParser()
    xml.XML.withSAXParser(saxParser)
}

What are your thoughts about this feature request? I can try to have a go at at getting this done myself and raise a PR but wanted to run this by you first as per your contributing guidelines state.