Skip to content

Commit

Permalink
Merge pull request #542 from SethTisue/issue541
Browse files Browse the repository at this point in the history
  • Loading branch information
SethTisue authored Jul 19, 2021
2 parents 272b573 + e826be8 commit 08e5fec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,22 @@ class ConstructingParserTest {
@Test
def SI6341issue65: Unit = {
val str = """<elem one="test" two="test2" three="test3"/>"""
val cpa = ConstructingParser.fromSource(io.Source.fromString(str), preserveWS = true)
val cpa = ConstructingParser.fromSource(Source.fromString(str), preserveWS = true)
val cpadoc = cpa.document()
val ppr = new PrettyPrinter(80,5)
val out = ppr.format(cpadoc.docElem)
assertEquals(str, out)
}

// https://github.com/scala/scala-xml/issues/541
@Test
def issue541: Unit = {
val xml =
"""|<script>// <![CDATA[
|[]; // ]]>
|</script>""".stripMargin
val parser = ConstructingParser.fromSource(Source.fromString(xml), preserveWS = true)
parser.document().docElem // shouldn't crash
}

}
5 changes: 4 additions & 1 deletion shared/src/main/scala/scala/xml/parsing/MarkupParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
protected var curInput: Source = input

// See ticket #3720 for motivations.
private class WithLookAhead(underlying: Source) extends Source {
// As for why it's `private[parsing]` rather than merely `private`, see
// https://github.com/scala/scala-xml/issues/541 ; the broader access is necessary,
// for now anyway, to work around https://github.com/lampepfl/dotty/issues/13096
private[parsing] class WithLookAhead(underlying: Source) extends Source {
private val queue = scala.collection.mutable.Queue[Char]()
def lookahead(): BufferedIterator[Char] = {
val iter = queue.iterator ++ new Iterator[Char] {
Expand Down

0 comments on commit 08e5fec

Please sign in to comment.