Skip to content

fix #541 by working around Scala 3 compiler bug #542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2021
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