mirror of
https://github.com/zeux/pugixml.git
synced 2024-12-26 21:04:25 +08:00
Don't escape attribute quotation symbol
When using double quotes for attributes, we don't need to escape '; when using single quotes, we don't need to escape ". This changes behavior to match 1.9 by default (where we don't escape '). Contributes to #272.
This commit is contained in:
parent
44e4d7e40b
commit
946de603b1
@ -3930,11 +3930,17 @@ PUGI__NS_BEGIN
|
|||||||
++s;
|
++s;
|
||||||
break;
|
break;
|
||||||
case '"':
|
case '"':
|
||||||
writer.write('&', 'q', 'u', 'o', 't', ';');
|
if (flags & format_attribute_single_quote)
|
||||||
|
writer.write('"');
|
||||||
|
else
|
||||||
|
writer.write('&', 'q', 'u', 'o', 't', ';');
|
||||||
++s;
|
++s;
|
||||||
break;
|
break;
|
||||||
case '\'':
|
case '\'':
|
||||||
writer.write('&', 'a', 'p', 'o', 's', ';');
|
if (flags & format_attribute_single_quote)
|
||||||
|
writer.write('&', 'a', 'p', 'o', 's', ';');
|
||||||
|
else
|
||||||
|
writer.write('\'');
|
||||||
++s;
|
++s;
|
||||||
break;
|
break;
|
||||||
default: // s is not a usual symbol
|
default: // s is not a usual symbol
|
||||||
|
@ -193,7 +193,8 @@ TEST_XML(write_escape, "<node attr=''>text</node>")
|
|||||||
doc.child(STR("node")).attribute(STR("attr")) = STR("<>'\"&\x04\r\n\t");
|
doc.child(STR("node")).attribute(STR("attr")) = STR("<>'\"&\x04\r\n\t");
|
||||||
doc.child(STR("node")).first_child().set_value(STR("<>'\"&\x04\r\n\t"));
|
doc.child(STR("node")).first_child().set_value(STR("<>'\"&\x04\r\n\t"));
|
||||||
|
|
||||||
CHECK_NODE(doc, STR("<node attr=\"<>'"& 	\"><>'\"&\r\n\t</node>"));
|
CHECK_NODE(doc, STR("<node attr=\"<>'"& 	\"><>'\"&\r\n\t</node>"));
|
||||||
|
CHECK_NODE_EX(doc, STR("<node attr='<>'\"& 	'><>'\"&\r\n\t</node>"), STR(""), format_raw | format_attribute_single_quote);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_XML(write_escape_roundtrip, "<node attr=''>text</node>")
|
TEST_XML(write_escape_roundtrip, "<node attr=''>text</node>")
|
||||||
@ -207,7 +208,8 @@ TEST_XML(write_escape_roundtrip, "<node attr=''>text</node>")
|
|||||||
|
|
||||||
// Note: this string is almost identical to the string from write_escape with the exception of \r
|
// Note: this string is almost identical to the string from write_escape with the exception of \r
|
||||||
// \r in PCDATA doesn't roundtrip because it has to go through newline conversion (which could be disabled, but is active by default)
|
// \r in PCDATA doesn't roundtrip because it has to go through newline conversion (which could be disabled, but is active by default)
|
||||||
CHECK_NODE(doc, STR("<node attr=\"<>'"& 	\"><>'\"&\n\t</node>"));
|
CHECK_NODE(doc, STR("<node attr=\"<>'"& 	\"><>'\"&\n\t</node>"));
|
||||||
|
CHECK_NODE_EX(doc, STR("<node attr='<>'\"& 	'><>'\"&\n\t</node>"), STR(""), format_raw | format_attribute_single_quote);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_XML(write_escape_unicode, "<node attr='㰀'/>")
|
TEST_XML(write_escape_unicode, "<node attr='㰀'/>")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user