Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.0-JSR-5
-
None
-
None
-
sun JDK 1.5.0_05-b05. Ubuntu linux.
Description
element values and attributes are not escaped if they contain a newline.
This script:
import groovy.xml.MarkupBuilder
xml = new MarkupBuilder()
xml.body {
xml.text("not escaped: & < >\n & < >")
}
produces this output:
<body>
<text>not escaped: & < >
& < ></text>
</body>
if I remove the newline in the text I get the correct output:
// newline removed
import groovy.xml.MarkupBuilder
xml = new MarkupBuilder()
xml.body {
xml.text("not escaped: & < > & < >")
}
output:
<body>
<text>not escaped: & < > & < ></text>
</body>
I've worked around this by subclassing MarkupBuilder and calling org.apache.commons.lang.StringEscapeUtils.escapeHtml in transformValue. Similar escaping needs to be done in MarkupBuilder.
import org.apache.commons.lang.StringEscapeUtils;
class EscapingMarkupBuilder extends MarkupBuilder {
public EscapingMarkupBuilder(PrintWriter writer)
// use alternate escaping to work around the bug.
protected String transformValue(String value)
}