+ sb.append("/>")
+ sp()
+ ser(ns :: r, pscopes, spaced, toClose)
+ } else {
+ sb.append('>')
+ val csp = e.child.forall(isAtomAndNotText)
+ ser(e.child.toList :: ns :: r, e.scope :: pscopes, csp :: spaced, e :: toClose)
+ }
+ case n => throw new IllegalArgumentException("Don't know how to serialize a " + n.getClass.getName)
+ }
}
+ ser(List(ns.toList), List(pscope), List(spaced), Nil)
+ }
def sequenceToXML(
children: Seq[Node],
@@ -243,20 +273,11 @@ object Utility extends AnyRef with parsing.TokenTests {
stripComments: Boolean = false,
decodeEntities: Boolean = true,
preserveWhitespace: Boolean = false,
- minimizeTags: MinimizeMode.Value = MinimizeMode.Default): Unit =
- {
- if (children.isEmpty) return
- else if (children forall isAtomAndNotText) { // add space
- val it = children.iterator
- val f = it.next()
- serialize(f, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags)
- while (it.hasNext) {
- val x = it.next()
- sb.append(' ')
- serialize(x, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags)
- }
- } else children foreach { serialize(_, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) }
- }
+ minimizeTags: MinimizeMode.Value = MinimizeMode.Default
+ ): Unit = if (children.nonEmpty) {
+ val spaced = children.forall(isAtomAndNotText)
+ serializeImpl(children, pscope, spaced, stripComments, minimizeTags, sb)
+ }
/**
* Returns prefix of qualified name if any.
diff --git a/shared/src/test/scala/scala/xml/UtilityTest.scala b/shared/src/test/scala/scala/xml/UtilityTest.scala
index a27fb0b1a..b7eb95a80 100644
--- a/shared/src/test/scala/scala/xml/UtilityTest.scala
+++ b/shared/src/test/scala/scala/xml/UtilityTest.scala
@@ -217,4 +217,10 @@ class UtilityTest {
val x = {Text(" My name ")}{Text(" is ")}{Text(" Harry ")}
assertEquals(My name is Harry
, Utility.trim(x))
}
+
+ @Test
+ def toStringStackSafe(): Unit = {
+ val xml = (1 to 5000).foldRight() { case (_, n) => {n} }
+ xml.toString
+ }
}