Skip to content

scala.xml.Utility.trim() doesn't properly handle adjacent Text nodes #3062

Closed
@scabug

Description

@scabug

if Text("My name is ") followed by Text("Harry") the space following the word "is" will be incorrectly trimmed out. Adjacent Text nodes need to be combined before whitespace is removed.

scala> import scala.xml._
import scala.xml._

scala> <div>{Text("My name is ")}{Text("Harry")}</div>
res0: scala.xml.Elem = <div>My name is Harry</div>

scala> Utility.trim(res0)
res1: scala.xml.Node = <div>My name isHarry</div>

This is important when modifying XML and then trimming it. For example we might start with

My name is user:name/
and then replace the user:name/ Elem with "Harry" thus leading to the adjacent Text nodes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions