Skip to content

Fix XMLEventReader does not handle ' properly #85

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions jvm/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,40 @@ class XMLEventReaderTest {
while(er.hasNext) er.next()
er.stop()
}

@Test
def entityRefTest: Unit = {
val source = Source.fromString("<text>&quot;&apos;&lt;&gt;&amp;</text>")
val er = new XMLEventReader(source)

assertTrue(er.next match {
case EvElemStart(_, "text", _, _) => true
case _ => false
})
assertTrue(er.next match {
case EvEntityRef("quot") => true
case e => false
})
assertTrue(er.next match {
case EvEntityRef("apos") => true
case _ => false
})
assertTrue(er.next match {
case EvEntityRef("lt") => true
case _ => false
})
assertTrue(er.next match {
case EvEntityRef("gt") => true
case _ => false
})
assertTrue(er.next match {
case EvEntityRef("amp") => true
case _ => false
})
assertTrue(er.next match {
case EvElemEnd(_, "text") => true
case _ => false
})
assert(er.isEmpty)
}
}
2 changes: 1 addition & 1 deletion shared/src/main/scala/scala/xml/Utility.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ object Utility extends AnyRef with parsing.TokenTests {
* For reasons unclear escape and unescape are a long ways from
* being logical inverses.
*/
val pairs = Map(
private val pairs = Map(
Copy link
Member

Choose a reason for hiding this comment

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

Maybe annotate it as @deprecated first just in case a user happened to be importing it?

"lt" -> '<',
"gt" -> '>',
"amp" -> '&',
Expand Down
13 changes: 7 additions & 6 deletions shared/src/main/scala/scala/xml/parsing/MarkupParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package parsing

import scala.io.Source
import scala.xml.dtd._
import Utility.Escapes.{ pairs => unescape }
import Utility.Escapes.unescMap

/**
* An XML parser.
Expand Down Expand Up @@ -470,11 +470,12 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
case _ => // EntityRef
val n = xName
xToken(';')

if (unescape contains n) {
handle.entityRef(tmppos, n)
ts &+ unescape(n)
} else push(n)
unescMap.get(n) match {
case None => push(n)
case Some(theChar) =>
handle.entityRef(tmppos, n)
ts &+ theChar
}
}
case _ => // text content
appendText(tmppos, ts, xText)
Expand Down