0
0
mirror of https://github.com/zeux/pugixml.git synced 2024-12-28 06:10:55 +08:00

XPath: Make sure step_push is called with valid nodes

Some steps relied on step_push rejecting null inputs; this is no longer
the case. Additionally stepping now more rigorously filters null inputs.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1069 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
Arseny Kapoulkine 2014-10-21 03:33:37 +00:00
parent 45b6315d99
commit 7774cdd96e
2 changed files with 27 additions and 4 deletions

View File

@ -8705,7 +8705,7 @@ PUGI__NS_BEGIN
while (cur && !cur.next_sibling()) cur = cur.parent();
cur = cur.next_sibling();
for (;;)
while (cur)
{
if (step_push(ns, cur, alloc) & once)
return;
@ -8733,7 +8733,7 @@ PUGI__NS_BEGIN
while (cur && !cur.previous_sibling()) cur = cur.parent();
cur = cur.previous_sibling();
for (;;)
while (cur)
{
if (cur.last_child())
cur = cur.last_child();
@ -8916,7 +8916,7 @@ PUGI__NS_BEGIN
if (it->node())
step_fill(ns, it->node(), stack.result, once, v);
else if (axis_has_attributes)
else if (axis_has_attributes && it->attribute() && it->parent())
step_fill(ns, it->attribute(), it->parent(), stack.result, once, v);
apply_predicates(ns, size, stack);
@ -8926,7 +8926,7 @@ PUGI__NS_BEGIN
{
if (c.n.node())
step_fill(ns, c.n.node(), stack.result, once, v);
else if (axis_has_attributes)
else if (axis_has_attributes && c.n.attribute() && c.n.parent())
step_fill(ns, c.n.attribute(), c.n.parent(), stack.result, once, v);
apply_predicates(ns, 0, stack);

View File

@ -616,4 +616,27 @@ TEST_XML(xpath_paths_optimize_step_once, "<node><para1><para2/><para3/><para4><p
CHECK_XPATH_BOOLEAN(doc, STR("//@attr5/following::para6"), true);
CHECK_XPATH_STRING(doc, STR("name(//@attr5/following::para6)"), STR("para6"));
}
TEST_XML(xpath_paths_null_nodeset_entries, "<node attr='value'/>")
{
xpath_node nodes[] =
{
xpath_node(doc.first_child()),
xpath_node(xml_node()),
xpath_node(doc.first_child().first_attribute(), doc.first_child()),
xpath_node(xml_attribute(), doc.first_child()),
xpath_node(xml_attribute(), xml_node()),
};
xpath_node_set ns(nodes, nodes + sizeof(nodes) / sizeof(nodes[0]));
xpath_variable_set vars;
vars.set(STR("x"), ns);
xpath_node_set rs = xpath_query("$x/.", &vars).evaluate_node_set(xml_node());
CHECK(rs.size() == 2);
CHECK(rs[0] == nodes[0]);
CHECK(rs[1] == nodes[2]);
}
#endif