0
0
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:
Arseny Kapoulkine 2019-09-11 21:27:20 -07:00
parent 44e4d7e40b
commit 946de603b1
2 changed files with 12 additions and 4 deletions

View File

@ -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

View File

@ -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=\"&lt;&gt;&apos;&quot;&amp;&#04;&#13;&#10;&#09;\">&lt;&gt;'\"&amp;&#04;\r\n\t</node>")); CHECK_NODE(doc, STR("<node attr=\"&lt;&gt;'&quot;&amp;&#04;&#13;&#10;&#09;\">&lt;&gt;'\"&amp;&#04;\r\n\t</node>"));
CHECK_NODE_EX(doc, STR("<node attr='&lt;&gt;&apos;\"&amp;&#04;&#13;&#10;&#09;'>&lt;&gt;'\"&amp;&#04;\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=\"&lt;&gt;&apos;&quot;&amp;&#04;&#13;&#10;&#09;\">&lt;&gt;'\"&amp;&#04;\n\t</node>")); CHECK_NODE(doc, STR("<node attr=\"&lt;&gt;'&quot;&amp;&#04;&#13;&#10;&#09;\">&lt;&gt;'\"&amp;&#04;\n\t</node>"));
CHECK_NODE_EX(doc, STR("<node attr='&lt;&gt;&apos;\"&amp;&#04;&#13;&#10;&#09;'>&lt;&gt;'\"&amp;&#04;\n\t</node>"), STR(""), format_raw | format_attribute_single_quote);
} }
TEST_XML(write_escape_unicode, "<node attr='&#x3c00;'/>") TEST_XML(write_escape_unicode, "<node attr='&#x3c00;'/>")