diff options
author | Paul Phillips <paulp@improving.org> | 2009-05-01 17:11:56 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-05-01 17:11:56 +0000 |
commit | 8cc51cc0dce7d86a4137eb636c4e3bed1b90cf13 (patch) | |
tree | 4187c272defe068a848bfbca6e1033e7f85ca85a | |
parent | a020e82b2e46dd49da6bb2b8ec4f5aaded246907 (diff) | |
download | scala-8cc51cc0dce7d86a4137eb636c4e3bed1b90cf13.tar.gz scala-8cc51cc0dce7d86a4137eb636c4e3bed1b90cf13.tar.bz2 scala-8cc51cc0dce7d86a4137eb636c4e3bed1b90cf13.zip |
Fix and test case for #1773.
-rw-r--r-- | src/library/scala/xml/Node.scala | 22 | ||||
-rw-r--r-- | test/files/run/t1773.scala | 12 |
2 files changed, 28 insertions, 6 deletions
diff --git a/src/library/scala/xml/Node.scala b/src/library/scala/xml/Node.scala index 197eed5ace..942220dc9e 100644 --- a/src/library/scala/xml/Node.scala +++ b/src/library/scala/xml/Node.scala @@ -129,13 +129,23 @@ abstract class Node extends NodeSeq { * @return <code>true</code> if .. */ override def equals(x: Any): Boolean = x match { - case g:Group => false + case g: Group => false case that: Node => - ((that.prefix == this.prefix ) - &&(that.label == this.label ) - &&(that.attributes == this.attributes) - && that.child.sameElements(this.child)) // sameElements - case _ => false + this.prefix == that.prefix && + this.label == that.label && + this.attributes == that.attributes && + equalChildren(that) + case _ => false + } + + // children comparison has to be done carefully - see bug #1773. + // It would conceivably be a better idea for a scala block which + // generates the empty string not to generate a child rather than + // our having to filter it later, but that approach would be more + // delicate to implement. + private def equalChildren(that: Node) = { + def noEmpties(xs: Seq[Node]) = xs filter (_.toString() != "") + noEmpties(this.child) sameElements noEmpties(that.child) } /** <p> diff --git a/test/files/run/t1773.scala b/test/files/run/t1773.scala new file mode 100644 index 0000000000..fc24f58b61 --- /dev/null +++ b/test/files/run/t1773.scala @@ -0,0 +1,12 @@ +object Test extends Application +{ + val xs = List( + <a></a>, + <a/>, + <a>{ xml.NodeSeq.Empty }</a>, + <a>{""}</a>, + <a>{ if (true) "" else "I like turtles" }</a> + ) + + for (x1 <- xs; x2 <- xs) assert (x1 == x2) +}
\ No newline at end of file |