Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML.save() dropped double quotation marks because &quot parsing #413

Closed
DenisNovac opened this issue Feb 10, 2020 · 8 comments · Fixed by #496
Closed

XML.save() dropped double quotation marks because &quot parsing #413

DenisNovac opened this issue Feb 10, 2020 · 8 comments · Fixed by #496
Milestone

Comments

@DenisNovac
Copy link

DenisNovac commented Feb 10, 2020

Hi everyone. I've read this lines with XML.loadFile(path):

<modified comment="EDITED oval:org.mitre.oval:obj:6886 - Adding the '&lt;behaviors windows_view=&quot;32_bit&quot; /&gt;' for oval:org.mitre.oval:obj:6886." date="2013-05-07T09:28:00.207-04:00">
              <contributor organization="ALTX-SOFT">Sergey Artykhov</contributor>
            </modified>

Then i saved them with XML.save(filepath, xml). Now i want to read this file back, but i can't:

Exception in thread "main" org.xml.sax.SAXParseException; lineNumber: 45; columnNumber: 82; Element type "modified" must be followed by either attribute specifications, ">" or "/>".
	at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:204)
	at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:178)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1471)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.seekCloseOfStartTag(XMLDocumentFragmentScannerImpl.java:1433)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1362)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2710)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:534)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:888)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1216)
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:635)
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:324)
	at scala.xml.factory.XMLLoader.loadXML(XMLLoader.scala:41)
	at scala.xml.factory.XMLLoader.loadXML$(XMLLoader.scala:37)
	at scala.xml.XML$.loadXML(XML.scala:58)
	at scala.xml.factory.XMLLoader.loadFile(XMLLoader.scala:48)
	at scala.xml.factory.XMLLoader.loadFile$(XMLLoader.scala:48)
	at scala.xml.XML$.loadFile(XML.scala:58)
	at composer.OvalIndexer$.$anonfun$indexDefinitions$1(OvalIndexer.scala:43)
	at scala.collection.StrictOptimizedIterableOps.map(StrictOptimizedIterableOps.scala:100)
	at scala.collection.StrictOptimizedIterableOps.map$(StrictOptimizedIterableOps.scala:87)
	at scala.collection.immutable.Vector.map(Vector.scala:119)
	at composer.OvalIndexer$.indexDefinitions(OvalIndexer.scala:40)
	at composer.OvalIndexer$.createIndex(OvalIndexer.scala:30)
	at Main$.main(Main.scala:11)
	at Main.main(Main.scala)

Inside my file:

<modified comment='EDITED oval:org.mitre.oval:obj:6886 - Adding the '&lt;behaviors windows_view="32_bit" /&gt;' for oval:org.mitre.oval:obj:6886.' date="2013-05-07T09:28:00.207-04:00">
              <contributor organization="ALTX-SOFT">Sergey Artykhov</contributor>
            </modified>

Looks like double quotation marks were lost somehow.

More examples:
Before:

<modified comment="EDITED oval:org.mitre.oval:obj:30168 - In some &quot;pattern match&quot; strings added &quot;\&quot; before &quot;.&quot; to clarify if &quot;point&quot; or &quot;any symbol&quot; needed." date="2014-07-28T18:11:00.493-04:00">
              <contributor organization="ALTX-SOFT">Evgeniy Pavlov</contributor>

After:

<modified comment='EDITED oval:org.mitre.oval:obj:30168 - In some "pattern match" strings added "\" before "." to clarify if "point" or "any symbol" needed.' date="2014-07-28T18:11:00.493-04:00">
              <contributor organization="ALTX-SOFT">Evgeniy Pavlov</contributor>
            </modified>
@DenisNovac DenisNovac changed the title XML.save() dropped double quotation marks XML.save() dropped double quotation marks because &quot parsing Feb 10, 2020
@DenisNovac
Copy link
Author

DenisNovac commented Feb 10, 2020

I've also tried to load XML like this:

val spf = SAXParserFactory.newInstance()
spf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true)
spf.setFeature("http://xml.org/sax/features/external-general-entities", false)
spf.setFeature("http://xml.org/sax/features/external-parameter-entities", false)

val saxParser = spf.newSAXParser()
val xml_parse = XML.withSAXParser(saxParser).loadFile(path)

But after saving XMLs are still broken.

@ashawley
Copy link
Member

Looks like it is a defect in 2.0.0-M1. If so, then it would mean #279 is a likely suspect. I only expected that change to affect PCDATA and CDATA. I didn't realize Text is used in the implementation for attributes. We'll need to either rework that change or revert it.

@DenisNovac
Copy link
Author

Switched to 1.2.0 and the error gone.

@ashawley ashawley added this to the 2.0 milestone Feb 11, 2020
@ashawley
Copy link
Member

Glad to hear that. We'll work on fixing in 2.0.0-M2. I appreciate you bothering to report this.

@SethTisue
Copy link
Member

SethTisue commented Feb 11, 2020

@DenisNovac nice catch! thanks for testing the milestone

@DenisNovac
Copy link
Author

No problem c:

@ashawley
Copy link
Member

ashawley commented Mar 3, 2021

One option is implementing something called AttributeText that is very similar to Text.

@SethTisue
Copy link
Member

#496

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants