summaryrefslogtreecommitdiff
path: root/tests/test_dom_modify.cpp
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-02-11 06:45:27 +0000
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-02-11 06:45:27 +0000
commit47c15ad949eb6589ee14d208444b4e759a611143 (patch)
tree35822cba8d2d3c6e5384c960ff8ea503bf3cf235 /tests/test_dom_modify.cpp
parent5fa25a878aa472530cfa981d374d6e9fe4e12c7c (diff)
Implement document fragment parsing.
Introduce a notable behavior change in default parsing mode: documents without a document element node are now considered invalid. This is technically a breaking change, however the amount of documents it affects is very small, all parsed data still persists, and lack of this check results in very confusing behavior in a number of cases. In order to be able to parse documents without an element node, a fragment parsing flag is introduced. Parsing a buffer in fragment mode treats the buffer as a fragment of a valid XML. As a consequence, top-level PCDATA is added to the tree; additionally, there are no restrictions on the number of nodes -- so documents without a document element are considered valid. Due to the way parsing works internally, load_buffer_inplace occasionally can not preserve the document contents if it's parsed in a fragment mode. While unfortunate, this problem is fundamental; since the use case is relatively obscure, hopefully documenting this shortcoming will be enough. git-svn-id: https://pugixml.googlecode.com/svn/trunk@980 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/test_dom_modify.cpp')
-rw-r--r--tests/test_dom_modify.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp
index c7a3989..c0f156b 100644
--- a/tests/test_dom_modify.cpp
+++ b/tests/test_dom_modify.cpp
@@ -1057,3 +1057,20 @@ TEST(dom_node_append_buffer_out_of_memory_buffer)
CHECK(doc.append_buffer(data, sizeof(data)).status == status_out_of_memory);
CHECK(!doc.first_child());
}
+
+TEST_XML(dom_node_append_buffer_fragment, "<node />")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(node.append_buffer("1", 1).status == status_no_document_element);
+ CHECK_NODE(doc, STR("<node>1</node>"));
+
+ CHECK(node.append_buffer("2", 1, parse_fragment));
+ CHECK_NODE(doc, STR("<node>12</node>"));
+
+ CHECK(node.append_buffer("3", 1).status == status_no_document_element);
+ CHECK_NODE(doc, STR("<node>123</node>"));
+
+ CHECK(node.append_buffer("4", 1, parse_fragment));
+ CHECK_NODE(doc, STR("<node>1234</node>"));
+}