Skip to content

Fix default namespace in PrettyPrinter.formatNodes #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/scala/scala/xml/PrettyPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class PrettyPrinter(width: Int, step: Int) {
* @param sb the stringbuffer to append to
*/
def format(n: Node, sb: StringBuilder) { // entry point
format(n, null, sb)
format(n, TopScope, sb)
}

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

/**
Expand Down
21 changes: 21 additions & 0 deletions src/test/scala/scala/xml/XMLTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -836,4 +836,25 @@ expected closing tag of foo
assertEquals("""<x:foo xmlns:x="gaga"/>""", pp.format(x))
}

@UnitTest
def nodeSeqNs: Unit = {
val x = {
<x:foo xmlns:x="abc"/><y:bar xmlns:y="def"/>
}
val pp = new PrettyPrinter(80, 2)
val expected = """<x:foo xmlns:x="abc"/><y:bar xmlns:y="def"/>"""
assertEquals(expected, pp.formatNodes(x))
}

@UnitTest
def nodeStringBuilder: Unit = {
val x = {
<x:foo xmlns:x="abc"/>
}
val pp = new PrettyPrinter(80, 2)
val expected = """<x:foo xmlns:x="abc"/>"""
val sb = new StringBuilder
pp.format(x, sb)
assertEquals(expected, sb.toString)
}
}