-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix(#16458): regression in xml syntax parsing #19522
Merged
odersky
merged 3 commits into
scala:main
from
i10416:fix/16458-xml-syntax-parse-regressions
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaced tests/pos/i16458.scala with tests/run/i16458.scala to make sure we get expected parse result. |
||
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 | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why my previous fix 624a6e0 used
ts.append(element)
instead ofcontent_LT(ts)
which is what scala 2 has. (I would expect the codebases not to diverge much.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why too, but I suspect it was just a mistake as
element
cannot consume XML special nodes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, current Scala 2 also uses content_LT instead of element
https://github.com/scala/scala/blob/8d598d102f0c2f23616ccd732e3ae93765da497a/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala#L392
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is what I was comparing. oh, my previous comment says just that.
It was a quick fix, but the scala 2 pr was also my quick fix, so I have no idea what happened that day. Thanks for following it up.