Skip to content

Commit a67af81

Browse files
committed
Fix #72 XMLEventReader does not handle ' properly
* src/main/scala/scala/xml/Utility.scala: Uncomment apos in Escapes map. (escape): Add case for apos. * src/test/scala/scala/xml/pull/XMLEventReaderTest.scala (entityRefTest): Unit test from Fehmi Can Saglam <fehmican.saglam@gmail.com>
1 parent 5b53104 commit a67af81

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

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

+4-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

@@ -123,6 +121,7 @@ object Utility extends AnyRef with parsing.TokenTests {
123121
case '>' => s.append("&gt;")
124122
case '&' => s.append("&amp;")
125123
case '"' => s.append("&quot;")
124+
case '\'' => s.append("&apos;")
126125
case '\n' => s.append('\n')
127126
case '\r' => s.append('\r')
128127
case '\t' => s.append('\t')

src/test/scala/scala/xml/UtilityTest.scala

+8-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ class UtilityTest {
3535
def aposEscaping: Unit = {
3636
val z = <bar>''</bar>
3737
val z1 = z.toString
38-
assertEquals("<bar>''</bar>", z1)
38+
assertEquals("<bar>&apos;&apos;</bar>", z1)
39+
}
40+
41+
@Test
42+
def quotEscaping: Unit = {
43+
val z = <bar>""</bar>
44+
val z1 = z.toString
45+
assertEquals("<bar>&quot;&quot;</bar>", z1)
3946
}
4047

4148
@Test

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)