Skip to content

Commit 14888a2

Browse files
committed
Merge pull request #50 from chrisloy/master
Fix default namespace in PrettyPrinter.formatNodes
2 parents 1498d97 + 7243aa0 commit 14888a2

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class PrettyPrinter(width: Int, step: Int) {
203203
* @param sb the stringbuffer to append to
204204
*/
205205
def format(n: Node, sb: StringBuilder) { // entry point
206-
format(n, null, sb)
206+
format(n, TopScope, sb)
207207
}
208208

209209
def format(n: Node, pscope: NamespaceBinding, sb: StringBuilder) { // entry point
@@ -253,7 +253,7 @@ class PrettyPrinter(width: Int, step: Int) {
253253
* @param nodes the sequence of nodes to be serialized
254254
* @param pscope the namespace to prefix mapping
255255
*/
256-
def formatNodes(nodes: Seq[Node], pscope: NamespaceBinding = null): String =
256+
def formatNodes(nodes: Seq[Node], pscope: NamespaceBinding = TopScope): String =
257257
sbToString(formatNodes(nodes, pscope, _))
258258

259259
/**

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

+21
Original file line numberDiff line numberDiff line change
@@ -836,4 +836,25 @@ expected closing tag of foo
836836
assertEquals("""<x:foo xmlns:x="gaga"/>""", pp.format(x))
837837
}
838838

839+
@UnitTest
840+
def nodeSeqNs: Unit = {
841+
val x = {
842+
<x:foo xmlns:x="abc"/><y:bar xmlns:y="def"/>
843+
}
844+
val pp = new PrettyPrinter(80, 2)
845+
val expected = """<x:foo xmlns:x="abc"/><y:bar xmlns:y="def"/>"""
846+
assertEquals(expected, pp.formatNodes(x))
847+
}
848+
849+
@UnitTest
850+
def nodeStringBuilder: Unit = {
851+
val x = {
852+
<x:foo xmlns:x="abc"/>
853+
}
854+
val pp = new PrettyPrinter(80, 2)
855+
val expected = """<x:foo xmlns:x="abc"/>"""
856+
val sb = new StringBuilder
857+
pp.format(x, sb)
858+
assertEquals(expected, sb.toString)
859+
}
839860
}

0 commit comments

Comments
 (0)