From 650a4c6cca98e3d1c973d86b91797e85f4861e6d Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Tue, 20 Jan 2015 20:37:14 -0800 Subject: Use string::append in implementations of xml_writer The current code is not optimal; since users actually read samples/tests change them to use faster (and shorter!) code. --- tests/test_write.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_write.cpp') diff --git a/tests/test_write.cpp b/tests/test_write.cpp index ca230c3..da83745 100644 --- a/tests/test_write.cpp +++ b/tests/test_write.cpp @@ -171,7 +171,7 @@ struct test_writer: xml_writer virtual void write(const void* data, size_t size) { CHECK(size % sizeof(pugi::char_t) == 0); - contents += std::basic_string(static_cast(data), static_cast(data) + size / sizeof(pugi::char_t)); + contents.append(static_cast(data), size / sizeof(pugi::char_t)); } }; -- cgit v1.2.3 From 604861e520d2d6579674a1c2bd5e59cb10f7ecd2 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Tue, 10 Mar 2015 09:03:22 -0700 Subject: Escape ?> sequence in PI value during printing This prevents malformed PI value from breaking the document structure. --- tests/test_write.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/test_write.cpp') diff --git a/tests/test_write.cpp b/tests/test_write.cpp index da83745..59cdb3e 100644 --- a/tests/test_write.cpp +++ b/tests/test_write.cpp @@ -115,6 +115,25 @@ TEST(write_pi_null) CHECK_NODE(doc, STR("")); } +TEST(write_pi_invalid) +{ + xml_document doc; + xml_node node = doc.append_child(node_pi); + + node.set_name(STR("test")); + node.set_value(STR("?")); + + CHECK_NODE(doc, STR("")); + + node.set_value(STR("?>")); + + CHECK_NODE(doc, STR("?>")); + + node.set_value(STR("")); + + CHECK_NODE(doc, STR("?>")); +} + TEST_XML_FLAGS(write_declaration, "", parse_declaration | parse_fragment) { CHECK_NODE(doc, STR("")); -- cgit v1.2.3