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/parsing/MarkupParser.scala:
	Import unescMap instead of pairs.

	* shared/src/main/scala/scala/xml/parsing/MarkupParserCommon.scala:
	Import unescMap instead of pairs.

	* jvm/src/main/scala/scala/xml/Utility.scala: Uncomment apos in
	unescape map.

	* jvm/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala (entityRefTest):
	Unit test from Fehmi Can Saglam <fehmican.saglam@gmail.com>
  • Loading branch information
ashawley committed Feb 6, 2017
1 parent 5f7601a commit f0a8b4e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
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)
}
}
11 changes: 4 additions & 7 deletions shared/src/main/scala/scala/xml/Utility.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,14 @@ object Utility extends AnyRef with parsing.TokenTests {
* For reasons unclear escape and unescape are a long ways from
* being logical inverses.
*/
val pairs = Map(
val unescMap = Map(
"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 = (unescMap - "apos") map { case (s, c) => c -> ("&%s;" format s) }
}
import Escapes.{ escMap, unescMap }

Expand Down
2 changes: 1 addition & 1 deletion 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 => unescape }

/**
* An XML parser.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package parsing

import scala.io.Source
import scala.annotation.switch
import Utility.Escapes.{ pairs => unescape }
import Utility.Escapes.{ unescMap => unescape }

import Utility.SU

Expand Down

0 comments on commit f0a8b4e

Please sign in to comment.