Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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