Skip to content

Commit 2c2b8cb

Browse files
committed
Unit tests for scala#35 OOM on malformed input
* src/test/scala/scala/xml/XMLTest.scala (issue35): New test. * src/test/scala/scala/xml/pull/XMLEventReaderTest.scala (issue35): New test.
1 parent ea9fdf8 commit 2c2b8cb

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/test/scala/scala/xml/XMLTest.scala

+6
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,12 @@ expected closing tag of foo
838838
assertEquals("""<x:foo xmlns:x="gaga"/>""", pp.format(x))
839839
}
840840

841+
@UnitTest( expected = classOf[scala.xml.SAXParseException] )
842+
def issue35: Unit = {
843+
val broken = "<broken attribute='is truncated"
844+
XML.loadString(broken)
845+
}
846+
841847
@UnitTest
842848
def nodeSeqNs: Unit = {
843849
val x = {

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package scala.xml.pull
1+
package scala.xml
2+
package pull
23

34
import org.junit.Test
45
import org.junit.Ignore
@@ -40,6 +41,17 @@ class XMLEventReaderTest {
4041
er.stop // allow thread to be garbage-collected
4142
}
4243

44+
@Test
45+
def issue35: Unit = {
46+
val broken = "<broken attribute='is truncated"
47+
val x = new Source {
48+
val iter = broken.iterator
49+
override def reportError(pos: Int, msg: String, out: java.io.PrintStream = Console.err) {}
50+
}
51+
val r = new XMLEventReader(x)
52+
assertTrue(r.next.isInstanceOf[EvElemStart])
53+
}
54+
4355
@Test(expected = classOf[Exception])
4456
def missingTagTest: Unit = {
4557
val data=

0 commit comments

Comments
 (0)