diff --git a/src/main/scala/scala/xml/parsing/MarkupParser.scala b/src/main/scala/scala/xml/parsing/MarkupParser.scala index 04e665023..d9a61b393 100755 --- a/src/main/scala/scala/xml/parsing/MarkupParser.scala +++ b/src/main/scala/scala/xml/parsing/MarkupParser.scala @@ -265,7 +265,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests { } if (1 != elemCount) { reportSyntaxError("document must contain exactly one element") - Console.println(children.toList) + //Console.println(children.toList) } doc.children = children @@ -389,7 +389,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests { def xComment: NodeSeq = { val sb: StringBuilder = new StringBuilder() xToken("--") - while (true) { + while (!eof) { if (ch == '-' && { sb.append(ch); nextch(); ch == '-' }) { sb.length = sb.length - 1 nextch() @@ -398,7 +398,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests { } else sb.append(ch) nextch() } - throw FatalError("this cannot happen") + throw truncatedError("broken comment") } /* todo: move this into the NodeBuilder class */ @@ -678,10 +678,10 @@ trait MarkupParser extends MarkupParserCommon with TokenTests { def markupDecl1() = { def doInclude() = { - xToken('['); while (']' != ch) markupDecl(); nextch() // ']' + xToken('['); while (']' != ch && !eof) markupDecl(); nextch() // ']' } def doIgnore() = { - xToken('['); while (']' != ch) nextch(); nextch() // ']' + xToken('['); while (']' != ch && !eof) nextch(); nextch() // ']' } if ('?' == ch) { nextch() @@ -747,7 +747,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests { case _ => curInput.reportError(pos, "unexpected character '" + ch + "', expected some markupdecl") - while (ch != '>') + while (ch != '>' && !eof) nextch() } } @@ -780,7 +780,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests { def intSubset() { //Console.println("(DEBUG) intSubset()") xSpace() - while (']' != ch) + while (']' != ch && !eof) markupDecl() } @@ -792,7 +792,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests { xSpace() val n = xName xSpace() - while ('>' != ch) { + while ('>' != ch && !eof) { //Console.println("["+ch+"]") putChar(ch) nextch() @@ -817,7 +817,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests { var attList: List[AttrDecl] = Nil // later: find the elemDecl for n - while ('>' != ch) { + while ('>' != ch && !eof) { val aname = xName xSpace() // could be enumeration (foo,bar) parse this later :-/ diff --git a/src/main/scala/scala/xml/parsing/MarkupParserCommon.scala b/src/main/scala/scala/xml/parsing/MarkupParserCommon.scala index 2e0568d12..72d669f21 100644 --- a/src/main/scala/scala/xml/parsing/MarkupParserCommon.scala +++ b/src/main/scala/scala/xml/parsing/MarkupParserCommon.scala @@ -247,7 +247,7 @@ private[scala] trait MarkupParserCommon extends TokenTests { while (true) { if (ch == head && peek(rest)) return handler(positioner(), sb.toString) - else if (ch == SU) + else if (ch == SU || eof) truncatedError("") // throws TruncatedXMLControl in compiler sb append ch diff --git a/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala b/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala index cf5b2504a..6b66326da 100644 --- a/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala +++ b/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala @@ -2,19 +2,20 @@ package scala.xml package pull import org.junit.Test -import org.junit.Ignore -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 -import org.junit.Assert.assertTrue -import org.junit.Assert.assertFalse -import org.junit.Assert.assertEquals +import org.junit.Assert.{assertFalse, assertTrue} import scala.io.Source +import scala.xml.parsing.FatalError class XMLEventReaderTest { val src = Source.fromString("!") + private def toSource(s: String) = new Source { + val iter = s.iterator + override def reportError(pos: Int, msg: String, out: java.io.PrintStream = Console.err) {} + } + @Test def pull: Unit = { val er = new XMLEventReader(src) @@ -44,17 +45,114 @@ class XMLEventReaderTest { @Test def issue35: Unit = { val broken = " + | + | | | @@ -66,8 +164,8 @@ class XMLEventReaderTest { | |""".stripMargin - val er = new XMLEventReader(Source.fromString(data)) - while(er.hasNext) er.next() - er.stop() - } + val er = new XMLEventReader(toSource(data)) + while(er.hasNext) er.next() + er.stop() + } }