Skip to content

Commit

Permalink
fix(#16458): regression in xml syntax parsing (#19522)
Browse files Browse the repository at this point in the history
close #16458
xLiteral mistakenly assumed that the element just after `<` is always
non-special element, but it is not true. It could be xCharData, comment,
xProcInstr.
  • Loading branch information
odersky authored Feb 15, 2024
2 parents b9f2ef0 + 9de9d57 commit 50d62f7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ object MarkupParsers {
while {
xSpaceOpt()
nextch()
ts.append(element)
content_LT(ts)
charComingAfter(xSpaceOpt()) == '<'
} do ()
handle.makeXMLseq(Span(start, curOffset, start), ts)
Expand Down
54 changes: 54 additions & 0 deletions tests/run/i16458.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

object Test {
import scala.xml.*
def main(args: Array[String]): Unit = {
val xml = <div>FooBar</div><!-- /.modal-content -->
assert(
xml match
case Seq(elm: Elem, comment: Comment) if
elm.label == "div" &&
elm.child(0) == Atom(Text("FooBar")) &&
comment.label == " /.modal-content "
=> true
case _ => false
,
xml
)
}
}

package scala.xml {
type MetaData = AnyRef

trait NamespaceBinding
object TopScope extends NamespaceBinding
object Null
abstract class Node {
def label: String
def child: Seq[Node]
override def toString = label + child.mkString
}
class Comment(commentText: String) extends Node{
def label = commentText
def child = Nil
}
class Elem(prefix: String, val label: String, attributes1: MetaData, scope: NamespaceBinding, minimizeEmpty: Boolean, val child: Node*) extends Node
class NodeBuffer extends Seq[Node] {
val nodes = scala.collection.mutable.ArrayBuffer.empty[Node]
def &+(o: Any): NodeBuffer =
o match {
case n: Node => nodes.addOne(n) ; this
case t: Text => nodes.addOne(Atom(t)) ; this
}
// Members declared in scala.collection.IterableOnce
def iterator: Iterator[scala.xml.Node] = nodes.iterator
// Members declared in scala.collection.SeqOps
def apply(i: Int): scala.xml.Node = nodes(i)
def length: Int = nodes.length
}
case class Text(text: String)
case class Atom(t: Text) extends Node {
def label = t.text
def child = Nil
}
}

0 comments on commit 50d62f7

Please sign in to comment.