Skip to content

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

Closed
@mbeckerle

Description

@mbeckerle

This issue migrated from https://issues.scala-lang.org/browse/SI-3062.

Please note: There is discussion there which is not reproduced here clarifying the needed algorithmic change.

Reproduced here is just the original description of the issue.

if Text("My name is ") followed by Text("Harry") the space following the word "is" will be incorrectly trimmed. 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 <div>My name is <user:name/></div> and then replace the <user:name/> Elem with "Harry" thus leading to the adjacent Text nodes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions