Fix interaction between parse_merge_pcdata and append_buffer
strconcat in the parsing loop only works if we know the source string comes from the same buffer that we're parsing. This is somewhat cumbersome to establish during parsing and it requires extra tracking data, so we just disable this combination as it's unlikely to be actually useful - usually append_buffer would be called on a possibly empty collection of elements, not on something with PCDATA.
This commit is contained in:
parent
f31ad2c1ab
commit
6749789ec4
@ -6307,6 +6307,9 @@ namespace pugi
|
||||
// append_buffer is only valid for elements/documents
|
||||
if (!impl::allow_insert_child(type(), node_element)) return impl::make_parse_result(status_append_invalid_root);
|
||||
|
||||
// append buffer can not merge PCDATA into existing PCDATA nodes
|
||||
if ((options & parse_merge_pcdata) != 0 && last_child().type() == node_pcdata) return impl::make_parse_result(status_append_invalid_root);
|
||||
|
||||
// get document node
|
||||
impl::xml_document_struct* doc = &impl::get_document(_root);
|
||||
|
||||
|
||||
@ -1334,6 +1334,22 @@ TEST(parse_merge_pcdata_whitespace)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(parse_merge_pcdata_append)
|
||||
{
|
||||
xml_document doc;
|
||||
doc.append_child(STR("node")).append_child(node_pcdata);
|
||||
xml_parse_result res = doc.child(STR("node")).append_buffer("hello <!--comment-->world", 25, parse_merge_pcdata | parse_fragment);
|
||||
|
||||
CHECK(res.status == status_append_invalid_root);
|
||||
CHECK_STRING(doc.child(STR("node")).first_child().value(), STR(""));
|
||||
|
||||
doc.child(STR("node")).remove_children();
|
||||
res = doc.child(STR("node")).append_buffer("hello <!--comment-->world", 25, parse_merge_pcdata | parse_fragment);
|
||||
|
||||
CHECK(res.status == status_ok);
|
||||
CHECK_STRING(doc.child(STR("node")).first_child().value(), STR("hello world"));
|
||||
}
|
||||
|
||||
TEST(parse_encoding_detect)
|
||||
{
|
||||
char test[] = "<?xml version='1.0' encoding='utf-8'?><n/>";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user