Skip to content

Commit e03e68e

Browse files
committed
Merge pull request #28 from ashawley/pretty-print-ns-defect
PrettyPrinter adds empty attribute with xmlns
2 parents b0a32fe + a53d11c commit e03e68e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/main/scala/scala/xml/PrettyPrinter.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class PrettyPrinter(width: Int, step: Int) {
244244
* @param pscope the namespace to prefix mapping
245245
* @return the formatted string
246246
*/
247-
def format(n: Node, pscope: NamespaceBinding = null): String =
247+
def format(n: Node, pscope: NamespaceBinding = TopScope): String =
248248
sbToString(format(n, pscope, _))
249249

250250
/**

src/test/scala/scala/xml/XMLTest.scala

+12
Original file line numberDiff line numberDiff line change
@@ -824,4 +824,16 @@ expected closing tag of foo
824824
}
825825
}
826826

827+
@UnitTest
828+
def issue28: Unit = {
829+
val x = <x:foo xmlns:x="gaga"/>
830+
// val ns = new NamespaceBinding("x", "gaga", sc)
831+
// val x = Elem("x", "foo", e, ns)
832+
val pp = new xml.PrettyPrinter(80, 2)
833+
// This assertion passed
834+
assertEquals("""<x:foo xmlns:x="gaga"/>""", x.toString)
835+
// This was the bug, producing an errant xmlns attribute
836+
assertEquals("""<x:foo xmlns:x="gaga"/>""", pp.format(x))
837+
}
838+
827839
}

0 commit comments

Comments
 (0)