summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library/scala/xml/Node.scala22
-rw-r--r--test/files/run/t1773.scala12
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