summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-07-01 20:32:47 +0000
committerPaul Phillips <paulp@improving.org>2010-07-01 20:32:47 +0000
commita0bacadc80bdf6adc8e0a31d64362082ffb3b142 (patch)
tree1e04c63650f67692854fd91751cca58c8d4f4177
parentdeaf94e5f2bcbd719c1b80dfba2aaf16eaa9f75e (diff)
downloadscala-a0bacadc80bdf6adc8e0a31d64362082ffb3b142.tar.gz
scala-a0bacadc80bdf6adc8e0a31d64362082ffb3b142.tar.bz2
scala-a0bacadc80bdf6adc8e0a31d64362082ffb3b142.zip
Fixed an infinite loop in the xml parser on inv...
Fixed an infinite loop in the xml parser on invalid input. Also found an off by one bug in Source while fixing it. No review.
-rw-r--r--src/library/scala/io/Source.scala10
-rw-r--r--src/library/scala/xml/parsing/MarkupParser.scala6
-rw-r--r--test/files/run/xml-loop-bug.checkbin0 -> 280 bytes
-rw-r--r--test/files/run/xml-loop-bug.scala5
4 files changed, 13 insertions, 8 deletions
diff --git a/src/library/scala/io/Source.scala b/src/library/scala/io/Source.scala
index 935fe022be..cb7403e255 100644
--- a/src/library/scala/io/Source.scala
+++ b/src/library/scala/io/Source.scala
@@ -198,7 +198,8 @@ abstract class Source extends Iterator[Char] {
*
*/
@deprecated("Use a collections method such as getLines().toIndexedSeq for random access.")
- def getLine(line: Int): String = getLines() drop (line - 1) next
+ def getLine(line: Int): String = lineNum(line)
+ private def lineNum(line: Int): String = getLines() drop (line - 1) next
class LineIterator() extends Iterator[String] {
private[this] val sb = new StringBuilder
@@ -298,11 +299,10 @@ abstract class Source extends Iterator[Char] {
* @param out PrintStream to use
*/
def report(pos: Int, msg: String, out: PrintStream) {
- val line = Position line pos
- val col = Position column pos
- val str = getLines() toIndexedSeq line
+ val line = Position line pos
+ val col = Position column pos
- out println "%s:%d:%d: %s%s%s^".format(descr, line, col, msg, str, spaces(col - 1))
+ out println "%s:%d:%d: %s%s%s^".format(descr, line, col, msg, lineNum(line), spaces(col - 1))
}
/**
diff --git a/src/library/scala/xml/parsing/MarkupParser.scala b/src/library/scala/xml/parsing/MarkupParser.scala
index 24e0d78c6f..4f6b89c07b 100644
--- a/src/library/scala/xml/parsing/MarkupParser.scala
+++ b/src/library/scala/xml/parsing/MarkupParser.scala
@@ -310,7 +310,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests
def xEntityValue(): String = {
val endch = ch
nextch
- while (ch != endch) {
+ while (ch != endch && !eof) {
putChar(ch)
nextch
}
@@ -556,7 +556,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests
if (ch != '\'' && ch != '"')
reportSyntaxError("quote ' or \" expected");
nextch
- while (ch != endch) {
+ while (ch != endch && !eof) {
putChar(ch)
nextch
}
@@ -572,7 +572,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests
if (ch!='\'' && ch != '"')
reportSyntaxError("quote ' or \" expected");
nextch
- while (ch != endch) {
+ while (ch != endch && !eof) {
putChar(ch)
//Console.println("hello '"+ch+"'"+isPubIDChar(ch));
if (!isPubIDChar(ch))
diff --git a/test/files/run/xml-loop-bug.check b/test/files/run/xml-loop-bug.check
new file mode 100644
index 0000000000..a31b93d0cf
--- /dev/null
+++ b/test/files/run/xml-loop-bug.check
Binary files differ
diff --git a/test/files/run/xml-loop-bug.scala b/test/files/run/xml-loop-bug.scala
new file mode 100644
index 0000000000..acb3c5c6da
--- /dev/null
+++ b/test/files/run/xml-loop-bug.scala
@@ -0,0 +1,5 @@
+object Test {
+ def main(args: Array[String]): Unit = {
+ scala.xml.parsing.ConstructingParser.fromSource(scala.io.Source.fromString("<!DOCTYPE xmeml SYSTEM> <xmeml> <sequence> </sequence> </xmeml> "), true).document.docElem
+ }
+}