-
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
fix(#16458): regression in xml syntax parsing #19522
Conversation
xLiteral mistakenly assumed that the element just after `<` is always non-special element, but it is not true. It could be xCharData, comment, xProcInstr.
tests/pos/i16458.scala
Outdated
@@ -0,0 +1,37 @@ | |||
def x = <div>FooBar</div><!-- /.modal-content --> | |||
|
|||
package scala.xml { |
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 copy-pasted and modifed code from tests/run/xml.scala. Without this, the test fails due to missing xml module.
@@ -371,10 +371,17 @@ object MarkupParsers { | |||
// parse more XML? | |||
if (charComingAfter(xSpaceOpt()) == '<') { | |||
while { | |||
xSpaceOpt() | |||
nextch() | |||
ts.append(element) |
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 of content_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.
I copied your test and just changed I didn't put in any brain power, but I see content_LT handles the empty element.
|
Just replacing element with content_LT, it works. See scala#19522 (comment)
Thank you. I checked it and it works! I added some precondition check in the previous commit because I suspected the |
Just replacing element with content_LT, it works. See scala#19522 (comment)
2a88851
to
27046fe
Compare
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 comment
The 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.
788fc43
to
8bdbe77
Compare
To check parsing properly, it is better to run a test and assert parse result.
8bdbe77
to
9de9d57
Compare
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 know very little about XML parsing but judging from the discussion everybody agrees this is OK.
Just replacing element with content_LT, it works. See #19522 (comment) [Cherry-picked 27046fe]
Just replacing element with content_LT, it works. See #19522 (comment) [Cherry-picked 27046fe]
Backports #19522 to the LTS branch. PR submitted by the release tooling. [skip ci]
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.