scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

Scala XML parsing crashes while parsing valid attribute values. #632

Closed scabug closed 13 years ago

scabug commented 16 years ago

This used to work in 2.7.0-RC2 but fails in 2.7.0-final. It seems & is decoded to an & by the underlying parser (the default one is Java's SAX parser), and the decoder is looking desperately for the end ';' token.

scala> XML.load(new java.io.StringReader("<test2 s=\"a&amp;\"></test2>"))
parsing attrib value: a&
java.util.NoSuchElementException
    at scala.RandomAccessSeq$$$$anon$$12.next(RandomAccessSeq.scala:144)
    at scala.xml.Utility$$.parseAttributeValue(Utility.scala:409)
    at scala.xml.UnprefixedAttribute.<init>(UnprefixedAttribute.scala:24)
    at scala.xml.parsing.FactoryAdapter$$$$anonfun$$startElement$$1.apply(FactoryAdapter.scala:155)
    at scala.xml.parsing.FactoryAdapter$$$$anonfun$$startElement$$1....
scabug commented 16 years ago

Imported From: https://issues.scala-lang.org/browse/SI-632?orig=1 Reporter: @dragos

scabug commented 16 years ago

@ingoem said: I just did a quick test. If this is scala.xml.XML that you are using, this one works for me.

Welcome to Scala version 2.7.0-final (Java HotSpot(TM) Client VM, Java 1.6.0_05-ea).
Type in expressions to have them evaluated.
Type :help for more information.

scala> scala.xml.XML.load(new java.io.StringReader("<test2 s=\"a&amp;\"></test2>"))
res0: scala.xml.Elem = <test2 s="a&amp;"></test2>
scabug commented 16 years ago

@dragos said: Replying to [comment:1 maier]:

I just did a quick test. If this is scala.xml.XML that you are using, this one works for me.

Try it with Java 5... I can't test it with Java 6 here, sorry. My guess is the XML parser shipped with Java 6 behaves differently. Here's the complete session:

iuliandragos@zrh-edu-10 ~ $$ scala
Welcome to Scala version 2.7.0-final (Java HotSpot(TM) Server VM, Java 1.5.0_07).
Type in expressions to have them evaluated.
Type :help for more information.

scala> scala.xml.XML.load(new java.io.StringReader("<test2 s=\"a&amp;\"></test2>"))
java.util.NoSuchElementException
        at scala.RandomAccessSeq$$$$anon$$12.next(RandomAccessSeq.scala:144)
        at scala.xml.Utility$$.parseAttributeValue(Utility.scala:408)
        at scala.xml.UnprefixedAttribute.<init>(UnprefixedAttribute.scala:24)
        at scala.xml.parsing.FactoryAdapter$$$$anonfun$$startElement$$1.apply(FactoryAdapter.scala:155)
        at scala.xml.parsing.FactoryAdapter$$$$anonfun$$startElement$$1....
scala> :q
scabug commented 16 years ago

Martin Ellis (mart) said: I see this between RC3 and final:

$$ /opt/scala-2.7.0-RC3/bin/scala
Welcome to Scala version 2.7.0-RC3 (Java HotSpot(TM) Server VM, Java 1.5.0_13).
Type in expressions to have them evaluated.
Type :help for more information.

scala> scala.xml.XML.loadString("<foo bar='&amp;' />");
res0: scala.xml.Elem = <foo bar="&amp;"></foo>

scala> exit

$$ /opt/scala-2.7.0-final/bin/scala
Welcome to Scala version 2.7.0-final (Java HotSpot(TM) Server VM, Java 1.5.0_13).
Type in expressions to have them evaluated.
Type :help for more information.

scala> scala.xml.XML.loadString("<foo bar='&amp;' />");
java.util.NoSuchElementException
        at scala.RandomAccessSeq$$$$anon$$12.next(RandomAccessSeq.scala:144)
        at scala.xml.Utility$$.parseAttributeValue(Utility.scala:408)
        at scala.xml.UnprefixedAttribute.<init>(UnprefixedAttribute.scala:24)
        at scala.xml.parsing.FactoryAdapter$$$$anonfun$$startElement$$1.apply(FactoryAdapter.scala:155)
        at scala.xml.parsing.FactoryAdapter$$$$anonfun$$startElement$$1....

Same result with Java 6. I was originally getting this problem with 2.7.0 from the maven repository.

Just to avoid any doubts, here's your expression again:

$$ /opt/scala-2.7.0-final/bin/scala
Welcome to Scala version 2.7.0-final (Java HotSpot(TM) Server VM, Java 1.5.0_13).
Type in expressions to have them evaluated.
Type :help for more information.

scala> scala.xml.XML.load(new java.io.StringReader("<test2 s=\"a&amp;\"></test2>"))
java.util.NoSuchElementException
        at scala.RandomAccessSeq$$$$anon$$12.next(RandomAccessSeq.scala:144)
        at scala.xml.Utility$$.parseAttributeValue(Utility.scala:408)
        at scala.xml.UnprefixedAttribute.<init>(UnprefixedAttribute.scala:24)
        at scala.xml.parsing.FactoryAdapter$$$$anonfun$$startElement$$1.apply(FactoryAdapter.scala:155)
        at scala.xml.parsing.FactoryAdapter$$$$anonfun$$startElement$$1....
scabug commented 16 years ago

Martin Ellis (mart) said: Oops. I should have included the weirdest bit:

scala> $$ /opt/scala-2.7.0-final/bin/scala
Welcome to Scala version 2.7.0-final (Java HotSpot(TM) Server VM, Java 1.6.0_03).
Type in expressions to have them evaluated.
Type :help for more information.

scala> scala.xml.XML.load(new java.io.StringReader("<test2 s=\"a&amp;\"></test2>"))
java.util.NoSuchElementException
        at scala.RandomAccessSeq$$$$anon$$12.next(RandomAccessSeq.scala:144)
        at scala.xml.Utility$$.parseAttributeValue(Utility.scala:408)
        at scala.xml.UnprefixedAttribute.<init>(UnprefixedAttribute.scala:24)
        at scala.xml.parsing.FactoryAdapter$$$$anonfun$$startElement$$1.apply(FactoryAdapter.scala:155)
        at scala.xml.parsing.FactoryAdapter$$$$anonfun$$startElement$$1....
scala>

What's different to maier's setup? I don't know why it works there, and not here.

scabug commented 16 years ago

@ingoem said: I just checked it again. Still works with Java 1.6 as well as 1.7. The only difference I see is the update number. I have Java 6 update 5 (1.6.0_05-ea) installed whereas mart has update 3 (1.6.0_03).

scabug commented 16 years ago

@ingoem said: Hmm, it even works with 1.5 for me:

Welcome to Scala version 2.7.0-final (Java HotSpot(TM) Client VM, Java 1.5.0_15).
Type in expressions to have them evaluated.
Type :help for more information.

scala> scala.xml.XML.load(new java.io.StringReader("<test2 s=\"a&amp;\"></test2>"))
res0: scala.xml.Elem = <test2 s="a&amp;"></test2>

I am on an Ubuntu Gutsy box, using Java from Sun's site and not the deb packages, if that matters.

scabug commented 16 years ago

@ingoem said: Note the higher update number again: 15 vs. 13 vs 7. Maybe they backported some bugfix? Just a wild guess though.

scabug commented 16 years ago

@dragos said: Replying to [comment:7 maier]:

Hmm, it even works with 1.5 for me:

Then the question is what version of the 2.7.0-final do you have? There was a release that was immediately retracted, and a second 2.7.0-final was issued later. Only the latter has the problem. Could you check that you have the latest (download-able) version? Otherwise I cannot understand this: I tried 1.6 and I get the same behavior (on Ubuntu... some sort). If there was any bug fix in 1.5 I would expect it to be included in 1.6. Right now I think (hope) that it is the scala version you have that is different. :)

scabug commented 16 years ago

@ingoem said: Replying to [comment:9 dragos]:

Then the question is what version of the 2.7.0-final do you have? There was a release that was immediately retracted, and a second 2.7.0-final was issued later. Only the latter has the problem.

You are right, I had the first release. I get the error with the current 2.7.0-final.

scabug commented 16 years ago

Martin Ellis (mart) said: The scala that claims to be 2.7.0-final in my sessions was downloaded yesterday (or early hours of this morning?).

So it's presumably the latter release - which is at least consistent with those findings, if I understood correctly.

Note to self: avoid use of the word 'final' in a release number :)

scabug commented 16 years ago

@burakemir said: fixed in r14461

scabug commented 15 years ago

@odersky said: Milestone 2.7.1 deleted