Skip to content

Commit 7243aa0

Browse files
committed
Default to TopScope if printing with StringBuilder
1 parent 4c3b8a2 commit 7243aa0

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

+1-1
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

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

+11
Original file line numberDiff line numberDiff line change
@@ -846,4 +846,15 @@ expected closing tag of foo
846846
assertEquals(expected, pp.formatNodes(x))
847847
}
848848

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+
}
849860
}

0 commit comments

Comments
 (0)