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: Add ignoreInvalidChars option to XmlParsing.parser #1106

Merged
merged 2 commits into from Jul 13, 2018

Conversation

takezoe
Copy link
Contributor

@takezoe takezoe commented Jul 12, 2018

When there are invalid bytes in XML, aalto-xml parser throws an exception like below:

[ERROR] [07/12/2018 17:57:02.332] [default-akka.actor.default-dispatcher-2] [akka://default/system/StreamSupervisor-0/flow-0-0-ignoreSink] Error in stage [akka.stream.alpakka.xml.Xml$StreamingXmlParser@110ba553]: Illegal XML character ((CTRL-CHAR, code 8))
 at [row,col {unknown-source}]: [10895,11]
com.fasterxml.aalto.WFCException: Illegal XML character ((CTRL-CHAR, code 8))
 at [row,col {unknown-source}]: [10895,11]
	at com.fasterxml.aalto.in.XmlScanner.reportInputProblem(XmlScanner.java:1333)
	at com.fasterxml.aalto.in.XmlScanner.handleInvalidXmlChar(XmlScanner.java:1526)
	at com.fasterxml.aalto.async.AsyncByteArrayScanner.parseCDataContents(AsyncByteArrayScanner.java:638)
	at com.fasterxml.aalto.async.AsyncByteArrayScanner.handleCDataStartMarker(AsyncByteArrayScanner.java:2061)
	at com.fasterxml.aalto.async.AsyncByteArrayScanner.handleCData(AsyncByteArrayScanner.java:1996)
	at com.fasterxml.aalto.async.AsyncByteArrayScanner.nextFromTree(AsyncByteArrayScanner.java:1218)
	at com.fasterxml.aalto.stax.StreamReaderImpl.next(StreamReaderImpl.java:760)
	at akka.stream.alpakka.xml.Xml$StreamingXmlParser$$anon$1.advanceParser(Xml.scala:236)
	at akka.stream.alpakka.xml.Xml$StreamingXmlParser$$anon$1.onPull(Xml.scala:226)
	at akka.stream.impl.fusing.GraphInterpreter.processPull(GraphInterpreter.scala:526)
	at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:422)
	at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:588)
	at akka.stream.impl.fusing.ActorGraphInterpreter$SimpleBoundaryEvent.execute(ActorGraphInterpreter.scala:45)
	at akka.stream.impl.fusing.ActorGraphInterpreter$SimpleBoundaryEvent.execute$(ActorGraphInterpreter.scala:41)
	at akka.stream.impl.fusing.ActorGraphInterpreter$BatchingActorInputBoundary$OnNext.execute(ActorGraphInterpreter.scala:78)
	at akka.stream.impl.fusing.GraphInterpreterShell.processEvent(ActorGraphInterpreter.scala:563)
	at akka.stream.impl.fusing.ActorGraphInterpreter.akka$stream$impl$fusing$ActorGraphInterpreter$$processEvent(ActorGraphInterpreter.scala:745)
	at akka.stream.impl.fusing.ActorGraphInterpreter$$anonfun$receive$1.applyOrElse(ActorGraphInterpreter.scala:760)
	at akka.actor.Actor.aroundReceive(Actor.scala:517)
	at akka.actor.Actor.aroundReceive$(Actor.scala:515)
	at akka.stream.impl.fusing.ActorGraphInterpreter.aroundReceive(ActorGraphInterpreter.scala:670)
	at akka.actor.ActorCell.receiveMessage(ActorCell.scala:588)
	at akka.actor.ActorCell.invoke(ActorCell.scala:557)
	at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:258)
	at akka.dispatch.Mailbox.run(Mailbox.scala:225)
	at akka.dispatch.Mailbox.exec(Mailbox.scala:235)
	at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
	at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
	at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
	at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

To handle invalid bytes, aalto-xml parser offers IllegalCharHandler. This pull request makes possible to ignore invalid bytes using IllegalCharHandler mechanism.

Copy link
Member

@2m 2m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Can add a test that would parse an xml with illegal characters?

@2m 2m added the p:xml label Jul 12, 2018
@takezoe
Copy link
Contributor Author

takezoe commented Jul 13, 2018

@2m Thanks for your review! I added two tests to make sure it fails with illegal characters in default and works ifignoreInvalidChars is enabled.

Copy link
Member

@2m 2m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. LGTM!

@2m 2m added this to the 0.21 milestone Jul 13, 2018
@2m 2m merged commit c82e49d into akka:master Jul 13, 2018
@takezoe takezoe deleted the xml-ignore-invalid-chars branch July 17, 2018 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants