Skip to content

Commit 11ae22d

Browse files
committed
Fix scala#72 XMLEventReader does not handle ' properly
* src/main/scala/scala/xml/Utility.scala: Uncomment apos in Escapes map. * src/test/scala/scala/xml/pull/XMLEventReaderTest.scala (entityRefTest): Unit test from Fehmi Can Saglam <[email protected]>
1 parent 55008bd commit 11ae22d

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/main/scala/scala/xml/Utility.scala

+3-5
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,11 @@ object Utility extends AnyRef with parsing.TokenTests {
9797
"lt" -> '<',
9898
"gt" -> '>',
9999
"amp" -> '&',
100-
"quot" -> '"'
101-
// enigmatic comment explaining why this isn't escaped --
102-
// is valid xhtml but not html, and IE doesn't know it, says jweb
103-
// "apos" -> '\''
100+
"quot" -> '"',
101+
"apos" -> '\''
104102
)
105103
val escMap = pairs map { case (s, c) => c -> ("&%s;" format s) }
106-
val unescMap = pairs ++ Map("apos" -> '\'')
104+
val unescMap = pairs
107105
}
108106
import Escapes.{ escMap, unescMap }
109107

src/test/scala/scala/xml/pull/XMLEventReaderTest.scala

+27-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package scala.xml
22
package pull
33

44
import org.junit.Test
5-
import org.junit.Assert.{assertFalse, assertTrue}
5+
import org.junit.Assert.{assertEquals,assertFalse, assertTrue}
66

77
import scala.io.Source
88
import scala.xml.parsing.FatalError
@@ -168,4 +168,30 @@ class XMLEventReaderTest {
168168
while(er.hasNext) er.next()
169169
er.stop()
170170
}
171+
172+
@Test
173+
def entityRefTest: Unit = { // SI-7796
174+
val source = Source.fromString("<text>&quot;&apos;&lt;&gt;&amp;</text>")
175+
val er = new XMLEventReader(source)
176+
177+
assertTrue(er.next match {
178+
case EvElemStart(_, "text", _, _) => true
179+
case _ => false
180+
})
181+
182+
val entities = Seq(
183+
EvEntityRef("quot"),
184+
EvEntityRef("apos"),
185+
EvEntityRef("lt"),
186+
EvEntityRef("gt"),
187+
EvEntityRef("amp"))
188+
189+
assertEquals(entities, er.take(entities.size).toSeq)
190+
191+
assertTrue(er.next match {
192+
case EvElemEnd(_, "text") => true
193+
case _ => false
194+
})
195+
assertTrue(er.isEmpty)
196+
}
171197
}

0 commit comments

Comments
 (0)