Skip to content

Commit 8f433bc

Browse files
dcaoyuanadriaanm
dcaoyuan
authored andcommitted
Fixed #3322wq
1 parent 1276924 commit 8f433bc

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

src/library/scala/xml/Utility.scala

+15-10
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,24 @@ object Utility extends AnyRef with parsing.TokenTests
194194
minimizeTags: Boolean = false): StringBuilder =
195195
{
196196
x match {
197-
case c: Comment if !stripComments => c buildString sb
198-
case x: SpecialNode => x buildString sb
199-
case g: Group => for (c <- g.nodes) toXML(c, x.scope, sb) ; sb
197+
case c: Comment => if (!stripComments) c buildString sb else sb
198+
case x: SpecialNode => x buildString sb
199+
case g: Group =>
200+
g.nodes foreach {toXML(_, x.scope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags)}
201+
sb
200202
case _ =>
201203
// print tag with namespace declarations
202204
sb.append('<')
203205
x.nameToString(sb)
204206
if (x.attributes ne null) x.attributes.buildString(sb)
205207
x.scope.buildString(sb, pscope)
206-
if (x.child.isEmpty && minimizeTags)
208+
if (x.child.isEmpty && minimizeTags) {
207209
// no children, so use short form: <xyz .../>
208210
sb.append(" />")
209-
else {
211+
} else {
210212
// children, so use long form: <xyz ...>...</xyz>
211213
sb.append('>')
212-
sequenceToXML(x.child, x.scope, sb, stripComments)
214+
sequenceToXML(x.child, x.scope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags)
213215
sb.append("</")
214216
x.nameToString(sb)
215217
sb.append('>')
@@ -221,20 +223,23 @@ object Utility extends AnyRef with parsing.TokenTests
221223
children: Seq[Node],
222224
pscope: NamespaceBinding = TopScope,
223225
sb: StringBuilder = new StringBuilder,
224-
stripComments: Boolean = false): Unit =
226+
stripComments: Boolean = false,
227+
decodeEntities: Boolean = true,
228+
preserveWhitespace: Boolean = false,
229+
minimizeTags: Boolean = false): Unit =
225230
{
226231
if (children.isEmpty) return
227232
else if (children forall isAtomAndNotText) { // add space
228233
val it = children.iterator
229234
val f = it.next
230-
toXML(f, pscope, sb)
235+
toXML(f, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags)
231236
while (it.hasNext) {
232237
val x = it.next
233238
sb.append(' ')
234-
toXML(x, pscope, sb)
239+
toXML(x, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags)
235240
}
236241
}
237-
else children foreach { toXML(_, pscope, sb) }
242+
else children foreach { toXML(_, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) }
238243
}
239244

240245
/**

src/library/scala/xml/Xhtml.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ object Xhtml
4949
(minimizableElements contains x.label)
5050

5151
x match {
52-
case c: Comment if !stripComments => c buildString sb
52+
case c: Comment => if (!stripComments) c buildString sb
5353
case er: EntityRef if decodeEntities => decode(er)
5454
case x: SpecialNode => x buildString sb
5555
case g: Group =>
56-
g.nodes foreach { toXhtml(_, x.scope, sb) }
56+
g.nodes foreach { toXhtml(_, x.scope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) }
5757

5858
case _ =>
5959
sb.append('<')
@@ -64,7 +64,7 @@ object Xhtml
6464
if (shortForm) sb.append(" />")
6565
else {
6666
sb.append('>')
67-
sequenceToXML(x.child, x.scope, sb)
67+
sequenceToXML(x.child, x.scope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags)
6868
sb.append("</")
6969
x.nameToString(sb)
7070
sb.append('>')
@@ -89,9 +89,9 @@ object Xhtml
8989

9090
val doSpaces = children forall isAtomAndNotText // interleave spaces
9191
for (c <- children.take(children.length - 1)) {
92-
toXhtml(c, pscope, sb)
92+
toXhtml(c, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags)
9393
if (doSpaces) sb append ' '
9494
}
95-
toXhtml(children.last, pscope, sb)
95+
toXhtml(children.last, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags)
9696
}
9797
}

0 commit comments

Comments
 (0)