Skip to content

Fix #72 XMLEventReader does not handle ' properly #89

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

Merged
merged 2 commits into from
May 24, 2017
Merged
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
26 changes: 25 additions & 1 deletion jvm/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package scala.xml
package pull

import org.junit.Test
import org.junit.Assert.{assertFalse, assertTrue}
import org.junit.Assert.{assertEquals,assertFalse, assertTrue}

import scala.io.Source
import scala.xml.parsing.FatalError
Expand Down Expand Up @@ -168,4 +168,28 @@ class XMLEventReaderTest {
while(er.hasNext) er.next()
er.stop()
}

@Test
def entityRefTest: Unit = { // SI-7796
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
})

assertEquals(EvEntityRef("quot"), er.next)
assertEquals(EvEntityRef("apos"), er.next)
assertEquals(EvEntityRef("lt"), er.next)
assertEquals(EvEntityRef("gt"), er.next)
assertEquals(EvEntityRef("amp"), er.next)

assertTrue(er.next match {
case EvElemEnd(_, "text") => true
case _ => false
})

assertTrue(er.isEmpty)
}
}
10 changes: 4 additions & 6 deletions shared/src/main/scala/scala/xml/Utility.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,11 @@ object Utility extends AnyRef with parsing.TokenTests {
"lt" -> '<',
"gt" -> '>',
"amp" -> '&',
"quot" -> '"'
// enigmatic comment explaining why this isn't escaped --
// is valid xhtml but not html, and IE doesn't know it, says jweb
// "apos" -> '\''
"quot" -> '"',
"apos" -> '\''
)
val escMap = pairs map { case (s, c) => c -> ("&%s;" format s) }
val unescMap = pairs ++ Map("apos" -> '\'')
val escMap = (pairs - "apos") map { case (s, c) => c -> ("&%s;" format s) }
val unescMap = pairs
}
import Escapes.unescMap

Expand Down