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

XMLEventReader does not handle HTML entities correctly #106

Closed
thisismana opened this issue Jun 20, 2016 · 1 comment
Closed

XMLEventReader does not handle HTML entities correctly #106

thisismana opened this issue Jun 20, 2016 · 1 comment

Comments

@thisismana
Copy link

(Created a new issue from a comment #72 (comment) by @Mark-L6n)

Furthermore, it does not handle other HTML entities well. There are well over 1,000 HTML entities (see list), and their values are simply tossed out with EvEntityRef. I am processing Wikipedia dumps and will encounter a wide range of them.
Why are only 4/5 entities processed, when any entity can occur in a text field? There shouldn't be a security concern, as a motivation for using entities is security.

Also, why are entities treated as an event at all? It'd be nice to have the option to disable this functionality so one could simply get all the text in a EvText() event.
Hopefully, there can be a way to either:

  1. enable EvEntityRef to process all HTML entities or
  2. disable EvEntityRef events from occurring and breaking up EvText() events.

Example problem:

object testEntityErr {
  import scala.io.Source
  import scala.xml.pull._

  val testStr = "<text> &amp; &quot; &lt; &gt; </text>" +
    "<notext> &nbsp; &apos; &copy; &reg; &euro; &dollar; &cent; &pound; &yen; </notext>"
  val xml = new XMLEventReader(Source.fromString(testStr))
  for (event <- xml) {
    event match {
      case EvEntityRef(e) => println(e)
      case EvComment(_) => println(event)
      case _ => // ignore
    }
  }
}

Output:

import scala.io.Source
import scala.xml.pull._

testStr: String = <text> &amp; &quot; &lt; &gt; </text><notext> &nbsp; &apos; &copy; &reg; &euro; &dollar; &cent; &pound; &yen; </notext>

xml: scala.xml.pull.XMLEventReader = non-empty iterator
amp
quot
lt
gt
EvComment( unknown entity nbsp; )
EvComment( unknown entity apos; )
EvComment( unknown entity copy; )
EvComment( unknown entity reg; )
EvComment( unknown entity euro; )
EvComment( unknown entity dollar; )
EvComment( unknown entity cent; )
EvComment( unknown entity pound; )
EvComment( unknown entity yen; )
res0: Unit = ()
@SethTisue
Copy link
Member

XMLEventReader will be deprecated entirely in the next release (#193, #199)

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

No branches or pull requests

2 participants