Skip to content

Fix doBuildString for TopScope of NamespaceBinding #47

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/main/scala/scala/xml/NamespaceBinding.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ case class NamespaceBinding(prefix: String, uri: String, parent: NamespaceBindin
shadowRedefined(stop).doBuildString(sb, stop)
}

private def doBuildString(sb: StringBuilder, stop: NamespaceBinding) {
protected def doBuildString(sb: StringBuilder, stop: NamespaceBinding) {
if ((this == null) || (this eq stop)) return // contains?

val s = " xmlns%s=\"%s\"".format(
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/scala/xml/TopScope.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ object TopScope extends NamespaceBinding(null, null, null) {

override def buildString(stop: NamespaceBinding) = ""
override def buildString(sb: StringBuilder, ignore: NamespaceBinding) = {}
override protected def doBuildString(sb: StringBuilder, stop: NamespaceBinding) = {}
}
17 changes: 17 additions & 0 deletions src/test/scala/scala/xml/XMLTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,23 @@ class XMLTest {
for (n <- cuckoo \ "_") {
assertEquals("http://cuckoo.com", n.namespace)
}
val actual: String = new scala.xml.PrettyPrinter(80, 5).format(cuckoo)
val expected = """|<cuckoo xmlns="http://cuckoo.com">
| <foo/>
| <bar/>
|</cuckoo>""".stripMargin
assertEquals(expected, actual)
}

@UnitTest
def namespacesWithNestedXmls: Unit = {
val foo = <f:foo xmlns:f="fooUrl"></f:foo>
val bar = <b:bar xmlns:b="barUrl">{foo}</b:bar>
val actual: String = new scala.xml.PrettyPrinter(80, 5).format(bar)
val expected = """|<b:bar xmlns:b="barUrl">
| <f:foo xmlns:f="fooUrl"></f:foo>
|</b:bar>""".stripMargin
assertEquals(expected, actual)
}

@UnitTest
Expand Down