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;
}
Activity
Jakub Neubauer
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Attachment | MarkupBuilder.java.patch [ 55165 ] |
Paul King
made changes -
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Assignee | Paul King [ paulk ] | |
| Fix Version/s | 1.8.1 [ 17223 ] | |
| Resolution | Fixed [ 1 ] |
Jakub Neubauer
made changes -
| Resolution | Fixed [ 1 ] | |
| Status | Resolved [ 5 ] | Reopened [ 4 ] |
Paul King
made changes -
| 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; } |
For example:
{code} import groovy.xml.* def xml = new MarkupBuilder() xml.test(a:"hello\nworld"){} {code} produces output: {code:xml} <test a='hello world' /> {code} 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): {code} 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; } {code} |
Jakub Neubauer
made changes -
| Attachment | repair.txt [ 55200 ] |
Paul King
made changes -
| Status | Reopened [ 4 ] | Resolved [ 5 ] |
| Resolution | Fixed [ 1 ] |
Paul King
made changes -
| Status | Resolved [ 5 ] | Closed [ 6 ] |