GNOME Bugzilla – Bug 328896
Wrong path calculation in xmlGetNodePath
Last modified: 2006-05-05 08:18:58 UTC
Please describe the problem: When using xmlGetNodePath in tree.c the XPath is not calculated right for text and cdata nodes. Starting with line 4333 of the offical 2.6.23 release: } else if ((cur->type == XML_TEXT_NODE) || (cur->type == XML_CDATA_SECTION_NODE)) { sep = "/"; name = "text()"; next = cur->parent; /* * Thumbler index computation */ tmp = cur->prev; while (tmp != NULL) { if ((cur->type == XML_TEXT_NODE) || (cur->type == XML_CDATA_SECTION_NODE)) occur++; tmp = tmp->prev; } the result is that every text node gets its absolute child position as an index instead of an index relative to other text siblings. Fix: The condition should be checked against tmp->type instead of cur->type (which is obviously either text or cdata and doesn't really change through the loop) I found a reference to that problem in the archives but couldn't locate a bug report http://mail.gnome.org/archives/xml/2005-March/msg00146.html Thank you Liron Steps to reproduce: 1. Call xmlGetNodePath on any text node which is not the first child to see that it's returned index is its absolute index and not by type Actual results: Expected results: Does this happen every time? Other information:
Looks like a copy&paste bug. Fixed in CVS: tree.c, revision 1.364. Thanks for the report!