diff options
author | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2014-02-11 06:45:27 +0000 |
---|---|---|
committer | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2014-02-11 06:45:27 +0000 |
commit | 47c15ad949eb6589ee14d208444b4e759a611143 (patch) | |
tree | 35822cba8d2d3c6e5384c960ff8ea503bf3cf235 /tests/test_write.cpp | |
parent | 5fa25a878aa472530cfa981d374d6e9fe4e12c7c (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_write.cpp')
-rw-r--r-- | tests/test_write.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/tests/test_write.cpp b/tests/test_write.cpp index de6f03d..465d111 100644 --- a/tests/test_write.cpp +++ b/tests/test_write.cpp @@ -25,19 +25,19 @@ TEST_XML(write_pcdata, "<node attr='1'><child><sub/>text</child></node>") CHECK_NODE_EX(doc, STR("<node attr=\"1\">\n\t<child>\n\t\t<sub />\n\t\ttext\n\t</child>\n</node>\n"), STR("\t"), format_indent); } -TEST_XML(write_cdata, "<![CDATA[value]]>") +TEST_XML_FLAGS(write_cdata, "<![CDATA[value]]>", parse_cdata | parse_fragment) { CHECK_NODE(doc, STR("<![CDATA[value]]>")); CHECK_NODE_EX(doc, STR("<![CDATA[value]]>\n"), STR(""), 0); } -TEST_XML(write_cdata_empty, "<![CDATA[]]>") +TEST_XML_FLAGS(write_cdata_empty, "<![CDATA[]]>", parse_cdata | parse_fragment) { CHECK_NODE(doc, STR("<![CDATA[]]>")); CHECK_NODE_EX(doc, STR("<![CDATA[]]>\n"), STR(""), 0); } -TEST_XML(write_cdata_escape, "<![CDATA[value]]>") +TEST_XML_FLAGS(write_cdata_escape, "<![CDATA[value]]>", parse_cdata | parse_fragment) { CHECK_NODE(doc, STR("<![CDATA[value]]>")); @@ -51,26 +51,25 @@ TEST_XML(write_cdata_inner, "<node><![CDATA[value]]></node>") CHECK_NODE_EX(doc, STR("<node><![CDATA[value]]></node>\n"), STR(""), 0); } - -TEST_XML_FLAGS(write_comment, "<!--text-->", parse_default | parse_comments) +TEST_XML_FLAGS(write_comment, "<!--text-->", parse_comments | parse_fragment) { CHECK_NODE(doc, STR("<!--text-->")); CHECK_NODE_EX(doc, STR("<!--text-->\n"), STR(""), 0); } -TEST_XML_FLAGS(write_pi, "<?name value?>", parse_default | parse_pi) +TEST_XML_FLAGS(write_pi, "<?name value?>", parse_pi | parse_fragment) { CHECK_NODE(doc, STR("<?name value?>")); CHECK_NODE_EX(doc, STR("<?name value?>\n"), STR(""), 0); } -TEST_XML_FLAGS(write_declaration, "<?xml version='2.0'?>", parse_default | parse_declaration) +TEST_XML_FLAGS(write_declaration, "<?xml version='2.0'?>", parse_declaration | parse_fragment) { CHECK_NODE(doc, STR("<?xml version=\"2.0\"?>")); CHECK_NODE_EX(doc, STR("<?xml version=\"2.0\"?>\n"), STR(""), 0); } -TEST_XML_FLAGS(write_doctype, "<!DOCTYPE id [ foo ]>", parse_default | parse_doctype) +TEST_XML_FLAGS(write_doctype, "<!DOCTYPE id [ foo ]>", parse_doctype | parse_fragment) { CHECK_NODE(doc, STR("<!DOCTYPE id [ foo ]>")); CHECK_NODE_EX(doc, STR("<!DOCTYPE id [ foo ]>\n"), STR(""), 0); |