Skip to content

Commit

Permalink
Fix scala#72 XMLEventReader does not handle ' properly
Browse files Browse the repository at this point in the history
	* shared/src/main/scala/scala/xml/Utility.scala: Uncomment
	apos in unescape map.

	* jvm/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala
	(entityRefTest): Refactor unit test.
  • Loading branch information
ashawley committed Apr 28, 2017
1 parent ad72b1e commit 51b3cfc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
34 changes: 11 additions & 23 deletions 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 @@ -170,38 +170,26 @@ class XMLEventReaderTest {
}

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

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
})
assert(er.isEmpty)

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

0 comments on commit 51b3cfc

Please sign in to comment.