-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix(#16459) xml parse regression #19531
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1fc27df
fix(#16459): cannot parse text in xml literal with newline
i10416 3debae0
Merge branch 'master' into fix/16459-xml-parse-regression
i10416 c8d7ca1
tryfix(16459): xml literal in for comprehension
i10416 0423862
tryfix(16459): add more test cases
i10416 4b0fff5
tryfix(16459): workaround LARROW, but find a corner-case
i10416 3d156b6
fix(16459): add patch to syntax error
i10416 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 hidden or 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 hidden or 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,107 @@ | ||
object Test { | ||
import scala.xml.* | ||
def main(args: Array[String]): Unit = { | ||
|
||
val xml = if(true) { | ||
<script type="text/javascript"> | ||
'location.reload()' | ||
'foo bar' | ||
</script> | ||
} else <div>empty</div> | ||
|
||
assert( | ||
xml match | ||
case elm: Elem if | ||
elm.label == "script" | ||
&& elm.child.length == 1 | ||
&& elm.child(0) == Atom(Text("\n 'location.reload()'\n 'foo bar'\n ")) | ||
=> true | ||
case _ => false | ||
, | ||
xml | ||
) | ||
// Scala 3 syntax | ||
val auxiliary0 = if true then { | ||
<script type="text/javascript"> | ||
'location.reload()' | ||
'foo bar' | ||
</script> | ||
} else <div>empty</div> | ||
|
||
val auxiliary1 = if true then | ||
<script type="text/javascript"> | ||
'location.reload()' | ||
'foo bar' | ||
</script> | ||
else <div>empty</div> | ||
|
||
val auxiliary2 = if true then <div>A</div>else <div>B</div> | ||
|
||
// Note: | ||
// This does not pass in Scala 2.12.18 and 2.13.12 | ||
// due to "Sequence argument type annotation `: _*` cannot be used here:" | ||
val auxiliary3 = if(true) <div>A</div>else <div>B</div> | ||
|
||
// Note: This passes in Scala 2.12.18 and 2.13.12 too. | ||
val auxiliary4 = if(true) <div attr="...">A</div>else <div attr="...">B</div> | ||
|
||
// Pattern match without guard. | ||
// Note: This passes in Scala 2.12.18 and 2.13.12 too. | ||
val auxiliary5 = for (case _ @ <div>empty</div> <- Seq(xml)) yield () | ||
// Note: These pass in Scala 2.12.18 and 2.13.12. | ||
val auxiliary6 = for (case _ @ <div>empty</div><- Seq(xml)) yield () | ||
val auxiliary7 = for (case _ @ <div>empty</div><-Seq(xml)) yield () | ||
Comment on lines
+52
to
+53
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. The left arrow just after xml closing tag broke the parser. 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. Fixed |
||
// Pattern match with if guard. | ||
// Note: This passes in Scala 2.12.18 and 2.13.12 too. | ||
val auxiliary8 = for (case _ @ <foo>FooBar</foo> <- Seq(xml) if true) | ||
yield () | ||
// Note: These pass in Scala 2.12.18 and 2.13.12. | ||
val auxiliary9 = for (case _ @ <foo>FooBar</foo><- Seq(xml) if true) | ||
yield () | ||
val auxiliary10 = for (case _ @ <foo>FooBar</foo><-Seq(xml) if true) | ||
yield () | ||
|
||
} | ||
|
||
} | ||
|
||
package scala.xml { | ||
type MetaData = AnyRef | ||
|
||
class UnprefixedAttribute( | ||
val key: String, | ||
val value: Text, | ||
next1: MetaData | ||
) extends MetaData | ||
|
||
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 | ||
object Elem { | ||
def unapply(e:Elem):Option[(String,String,Any,Text,Any)] = Some(("dummy","dummy",null,null,null)) | ||
} | ||
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 | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.