Skip to content

XMLEventReader does not handle HTML entities correctly #106

Closed
@thisismana

Description

@thisismana

(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 = ()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions