From 3edc6b2cf5a86e0baf6bbcf5e1ab74d6cc581e0c Mon Sep 17 00:00:00 2001 From: "Aaron S. Hawley" Date: Fri, 12 Sep 2014 18:10:36 -0400 Subject: [PATCH 1/2] Unit test for #28 PrettyPrinter adds empty attribute with xmlns * src/test/scala/scala/xml/XMLTest.scala (issue28): New unit test --- src/test/scala/scala/xml/XMLTest.scala | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/scala/scala/xml/XMLTest.scala b/src/test/scala/scala/xml/XMLTest.scala index b86f2c9ef..01431baf1 100644 --- a/src/test/scala/scala/xml/XMLTest.scala +++ b/src/test/scala/scala/xml/XMLTest.scala @@ -824,4 +824,16 @@ expected closing tag of foo } } + @UnitTest + def issue28: Unit = { + val x = + // val ns = new NamespaceBinding("x", "gaga", sc) + // val x = Elem("x", "foo", e, ns) + val pp = new xml.PrettyPrinter(80, 2) + // This assertion passed + assertEquals("""""", x.toString) + // This was the bug, producing an errant xmlns attribute + assertEquals("""""", pp.format(x)) + } + } From a53d11c55bbf4dc60ebec28836276d46fbd1247a Mon Sep 17 00:00:00 2001 From: "Aaron S. Hawley" Date: Wed, 3 Dec 2014 14:09:09 -0500 Subject: [PATCH 2/2] Fix #28 by using TopScope instead of null * src/main/scala/com/jonasboner/PrettyPrinter.scala (format): Modify namespace binding default argument to TopScope, was null. --- src/main/scala/scala/xml/PrettyPrinter.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/scala/xml/PrettyPrinter.scala b/src/main/scala/scala/xml/PrettyPrinter.scala index 515c9c088..a175f1df2 100755 --- a/src/main/scala/scala/xml/PrettyPrinter.scala +++ b/src/main/scala/scala/xml/PrettyPrinter.scala @@ -244,7 +244,7 @@ class PrettyPrinter(width: Int, step: Int) { * @param pscope the namespace to prefix mapping * @return the formatted string */ - def format(n: Node, pscope: NamespaceBinding = null): String = + def format(n: Node, pscope: NamespaceBinding = TopScope): String = sbToString(format(n, pscope, _)) /**