0
0
mirror of https://github.com/zeux/pugixml.git synced 2025-01-14 01:47:55 +08:00

Refactor contents=0 behavior

Also change the error code to status_io_error
This commit is contained in:
Arseny Kapoulkine 2015-03-05 11:35:39 -08:00
parent 57ca94f897
commit 9749920c82
2 changed files with 5 additions and 8 deletions

View File

@ -4316,12 +4316,7 @@ PUGI__NS_BEGIN
PUGI__FN xml_parse_result load_buffer_impl(xml_document_struct* doc, xml_node_struct* root, void* contents, size_t size, unsigned int options, xml_encoding encoding, bool is_mutable, bool own, char_t** out_buffer)
{
// check input buffer
if ((contents==NULL) && (size!=0)) {
xml_parse_result result;
result.status = status_no_document_element;
return result;
}
if (!contents && size) return make_parse_result(status_io_error);
// get actual encoding
xml_encoding buffer_encoding = impl::get_buffer_encoding(encoding, contents, size);

View File

@ -872,14 +872,16 @@ TEST(parse_load_buffer_null)
{
xml_document doc;
CHECK(doc.load_buffer(0, 12).status == status_no_document_element && !doc.first_child());
CHECK(doc.load_buffer(0, 12).status == status_io_error && !doc.first_child());
CHECK(doc.load_buffer(0, 12, parse_fragment).status == status_io_error && !doc.first_child());
}
TEST(parse_load_buffer_empty)
{
xml_document doc;
CHECK(doc.load_buffer("foo", 0).status == status_no_document_element);
CHECK(doc.load_buffer("foo", 0).status == status_no_document_element && !doc.first_child());
CHECK(doc.load_buffer("foo", 0, parse_fragment) && !doc.first_child());
}
TEST(parse_out_of_memory)