Skip to content

Commit 3254347

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 ea9fdf8 commit 3254347

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
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

+26
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,30 @@ class XMLEventReaderTest {
5858
while(er.hasNext) er.next()
5959
er.stop()
6060
}
61+
62+
@Test
63+
def entityRefTest: Unit = { // SI-7796
64+
val source = Source.fromString("<text>&quot;&apos;&lt;&gt;&amp;</text>")
65+
val er = new XMLEventReader(source)
66+
67+
assertTrue(er.next match {
68+
case EvElemStart(_, "text", _, _) => true
69+
case _ => false
70+
})
71+
72+
val entities = Seq(
73+
EvEntityRef("quot"),
74+
EvEntityRef("apos"),
75+
EvEntityRef("lt"),
76+
EvEntityRef("gt"),
77+
EvEntityRef("amp"))
78+
79+
assertEquals(entities, er.take(entities.size).toSeq)
80+
81+
assertTrue(er.next match {
82+
case EvElemEnd(_, "text") => true
83+
case _ => false
84+
})
85+
assertTrue(er.isEmpty)
86+
}
6187
}

0 commit comments

Comments
 (0)