Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.8.0
-
Fix Version/s: 1.8.1
-
Component/s: XML Processing
-
Labels:None
-
Number of attachments :
Description
For example:
import groovy.xml.* def xml = new MarkupBuilder() xml.test(a:"hello\nworld"){}
produces output:
<test a='hello world' />
But xml specification says that when parsing, new lines in attribute value should be converted to single space. So they are not preserved.
I suggest this new method implementation (sorry that I don't provide real .patch):
private String checkForReplacement(boolean isAttrValue, char ch) {
switch (ch) {
case '&':
return "&";
case '<':
return "<";
case '>':
return ">";
case '"':
// The double quote is only escaped if the value is for
// an attribute and the builder is configured to output
// attribute values inside double quotes.
if (isAttrValue && useDoubleQuotes) return """;
break;
case '\'':
// The apostrophe is only escaped if the value is for an
// attribute, as opposed to element content, and if the
// builder is configured to surround attribute values with
// single quotes.
if (isAttrValue && !useDoubleQuotes) return "'";
break;
case '\n':
if(isAttrValue) return " ";
case '\r':
if(isAttrValue) return " ";
}
return null;
}
My previous comment was mangled, so I rather try to attach a patch.