Skip to content

Fix #8214 Don't consume whitespace after XML #8228

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
Feb 7, 2020
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
14 changes: 7 additions & 7 deletions compiler/src/dotty/tools/dotc/parsing/xml/MarkupParsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -362,18 +362,18 @@ object MarkupParsers {
tmppos = Span(curOffset) // Iuli: added this line, as it seems content_LT uses tmppos when creating trees
content_LT(ts)

// parse more XML ?
// parse more XML?
if (charComingAfter(xSpaceOpt()) == '<') {
xSpaceOpt()
while (ch == '<') {
nextch()
ts append element
while {
xSpaceOpt()
}
nextch()
ts.append(element)
charComingAfter(xSpaceOpt()) == '<'
} do ()
handle.makeXMLseq(Span(start, curOffset, start), ts)
}
else {
assert(ts.length == 1)
assert(ts.length == 1, "Require one tree")
ts(0)
}
},
Expand Down
42 changes: 42 additions & 0 deletions tests/run/xml.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

object Test {
import scala.xml.NodeBuffer

def main(args: Array[String]): Unit = {
val xml = <hello>world</hello>
assert(xml.toString == "helloworld")
val nodeBuffer: NodeBuffer = <hello/><world/>
assert(nodeBuffer.mkString == "helloworld")
}
}
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 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
}
}