From 44f8e80e7eb9c89236cd52f9a3128ff76369b0ad Mon Sep 17 00:00:00 2001 From: pamapa Date: Sun, 12 Jan 2020 12:12:15 +0100 Subject: [PATCH] fix: #320: " and ' encoding must also apply for PCDATA --- src/pugixml.cpp | 10 +++++----- tests/test_write.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 156a1f4..c7bf20b 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -1871,7 +1871,7 @@ PUGI__NS_BEGIN { 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 3, 3, 2, 3, 3, // 0-15 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 16-31 - 0, 0, 2, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 16, 16, 0, // 32-47 + 0, 0, 3, 0, 0, 0, 3, 3, 0, 0, 0, 0, 0, 16, 16, 0, // 32-47 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 0, 0, 3, 0, 1, 0, // 48-63 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, // 64-79 @@ -3930,17 +3930,17 @@ PUGI__NS_BEGIN ++s; break; case '"': - if (flags & format_attribute_single_quote) + if (type == ctx_special_attr && (flags & format_attribute_single_quote)) writer.write('"'); else writer.write('&', 'q', 'u', 'o', 't', ';'); ++s; break; case '\'': - if (flags & format_attribute_single_quote) - writer.write('&', 'a', 'p', 'o', 's', ';'); - else + if (type == ctx_special_attr && !(flags & format_attribute_single_quote)) writer.write('\''); + else + writer.write('&', 'a', 'p', 'o', 's', ';'); ++s; break; default: // s is not a usual symbol diff --git a/tests/test_write.cpp b/tests/test_write.cpp index 0410e82..80f97cc 100644 --- a/tests/test_write.cpp +++ b/tests/test_write.cpp @@ -193,8 +193,8 @@ TEST_XML(write_escape, "text") 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")); - CHECK_NODE(doc, STR("'"& \"><>'\"&\r\n\t")); - CHECK_NODE_EX(doc, STR("<>'\"&\r\n\t"), STR(""), format_raw | format_attribute_single_quote); + CHECK_NODE(doc, STR("'"& \"><>'"&\r\n\t")); + CHECK_NODE_EX(doc, STR("<>'"&\r\n\t"), STR(""), format_raw | format_attribute_single_quote); } TEST_XML(write_escape_roundtrip, "text") @@ -208,8 +208,8 @@ TEST_XML(write_escape_roundtrip, "text") // 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) - CHECK_NODE(doc, STR("'"& \"><>'\"&\n\t")); - CHECK_NODE_EX(doc, STR("<>'\"&\n\t"), STR(""), format_raw | format_attribute_single_quote); + CHECK_NODE(doc, STR("'"& \"><>'"&\n\t")); + CHECK_NODE_EX(doc, STR("<>'"&\n\t"), STR(""), format_raw | format_attribute_single_quote); } TEST_XML(write_escape_unicode, "")