scala-xml
scala-xml copied to clipboard
Characters unnecessarily escaped by toString method of XML elements
https://issues.scala-lang.org/browse/SI-5645
The buildString
method of Text
class seems broken(see https://github.com/scala/scala-xml/blob/e3d85ebdefe013a3bfd3baa2278b23ea526706c1/src/main/scala/scala/xml/Text.scala#L26). The possible workaround is to define VerbatimText
class and override buildString method without escape
functionality.
Maintainers, is PR needed?
Currently this is totally expected since XML has two different "values" one is CDATA and one is PCDATA. PCDATA means escaped values and all XML values are automatically escaped if you don't wrap your data with a CDATA field.
My comment on the scala ticket was:
toString encodes, but text does not. Pick one. Or, I wonder if ScalaTags has special smarts for scripters, embedding in comments etc.
This suggestion may be out of scope, but the API is confusing. toString
is not normally used for specialized string representations, arguably.
It seems nothing in the XML specification says that double quotes "
are an illegal character within the text of an element. So generally encoding them as """ seems somewhat arbitrary.
I found this to be an effective work around:
val verbatimAtom = new xml.Atom(verbatimText) {
override def buildString(sb: StringBuilder): StringBuilder =
sb.append(importMapStr)
}
fix was reverted because it caused https://github.com/scala/scala-xml/issues/413 — someone want to see if they can solve them both at once?