Skip to content

Commit

Permalink
Fix infinite loop in lexer on malformed XML processing instructions /…
Browse files Browse the repository at this point in the history
… unparsed
  • Loading branch information
mdr committed Apr 14, 2011
1 parent e3a3ba2 commit 4d1a1a8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -6,6 +6,7 @@
* FIX: incorrect indent behaviour for finally block after a catch block
* Add SpacesWithinPatternBinders preference (issue #15)
* Add MultilineScaladocCommentsStartOnFirstLine preference (issue #16)
* FIX: infinite loop in lexer on malformed XML processing instructions / unparsed

0.0.9 (26/February/11)

Expand Down
4 changes: 4 additions & 0 deletions scalariform/src/main/scala/scalariform/lexer/XmlLexer.scala
Expand Up @@ -244,6 +244,8 @@ trait XmlLexer extends Lexer {
if (lookaheadIs("</xml:unparsed>")) {
munch("</xml:unparsed>")
continue = false
} else if (ch == SU) {
if (forgiveLexerErrors) continue = false else throw new ScalaLexerException("Malformed Unparsed XML")
} else
nextChar()
}
Expand All @@ -257,6 +259,8 @@ trait XmlLexer extends Lexer {
if (lookaheadIs("?>")) {
munch("?>")
continue = false
} else if (ch == SU) {
if (forgiveLexerErrors) continue = false else throw new ScalaLexerException("Malformed XML processing instruction")
} else
nextChar()
}
Expand Down
Expand Up @@ -193,6 +193,9 @@ println("foo")""" producesTokens (VARID, LPAREN, STRING_LITERAL, RPAREN, WS, VAR

"Lexer" should "throw a lexer exception" in {
evaluating { ScalaLexer.rawTokenise("\"\"\"") } should produce[ScalaLexerException]
evaluating { ScalaLexer.rawTokenise("<?") } should produce[ScalaLexerException]
evaluating { ScalaLexer.rawTokenise("<xml:unparsed>") } should produce[ScalaLexerException]

}

{
Expand All @@ -203,6 +206,8 @@ println("foo")""" producesTokens (VARID, LPAREN, STRING_LITERAL, RPAREN, WS, VAR
"\"unclosed" producesTokens (STRING_LITERAL)
"\\ufoob" producesTokens (WS)
"`unclosed" producesTokens (VARID)
"<?" producesTokens (XML_PROCESSING_INSTRUCTION)
"<xml:unparsed>" producesTokens (XML_UNPARSED)

}

Expand Down

0 comments on commit 4d1a1a8

Please sign in to comment.