From 8cc51cc0dce7d86a4137eb636c4e3bed1b90cf13 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 1 May 2009 17:11:56 +0000 Subject: Fix and test case for #1773. --- src/library/scala/xml/Node.scala | 22 ++++++++++++++++------ test/files/run/t1773.scala | 12 ++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 test/files/run/t1773.scala 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 true 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) } /**

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( + , + , + { xml.NodeSeq.Empty }, + {""}, + { if (true) "" else "I like turtles" } + ) + + for (x1 <- xs; x2 <- xs) assert (x1 == x2) +} \ No newline at end of file -- cgit v1.2.3