mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
DOM: Fix get_dom_node_map_index() so it returns the correct ordered index
This was cause by the recent change to allocate string during incremental
parsing where the node string was set after insertion. Test for this in the
works.
Fixes: b6b6d3c67e
This commit is contained in:
parent
f268d0c495
commit
ea675cbb6e
@ -190,7 +190,8 @@ dom_node_list_bsearch(struct dom_node_search *search, struct dom_node_list *list
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int get_dom_node_map_index(struct dom_node_list *list, struct dom_node *node)
|
||||
int
|
||||
get_dom_node_map_index(struct dom_node_list *list, struct dom_node *node)
|
||||
{
|
||||
struct dom_node_search search = INIT_DOM_NODE_SEARCH(node, list);
|
||||
struct dom_node *match = dom_node_list_bsearch(&search, list);
|
||||
@ -327,6 +328,23 @@ init_dom_node_(unsigned char *file, int line,
|
||||
node->type = type;
|
||||
node->parent = parent;
|
||||
|
||||
/* Make it possible to add a node to a parent without allocating the
|
||||
* strings. */
|
||||
if (allocated >= 0) {
|
||||
node->allocated = !!allocated;
|
||||
} else if (parent) {
|
||||
node->allocated = parent->allocated;
|
||||
}
|
||||
|
||||
if (node->allocated) {
|
||||
if (!init_dom_string(&node->string, string->string, string->length)) {
|
||||
done_dom_node(node);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
copy_dom_string(&node->string, string);
|
||||
}
|
||||
|
||||
if (parent) {
|
||||
struct dom_node_list **list = get_dom_node_list(parent, node);
|
||||
int sort = (type == DOM_NODE_ATTRIBUTE);
|
||||
@ -342,22 +360,6 @@ init_dom_node_(unsigned char *file, int line,
|
||||
done_dom_node(node);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Make it possible to add a node to a parent without
|
||||
* allocating the strings. */
|
||||
node->allocated = allocated < 0 ? parent->allocated : !!allocated;
|
||||
|
||||
} else if (allocated >= 0) {
|
||||
node->allocated = !!allocated;
|
||||
}
|
||||
|
||||
if (node->allocated) {
|
||||
if (!init_dom_string(&node->string, string->string, string->length)) {
|
||||
done_dom_node(node);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
copy_dom_string(&node->string, string);
|
||||
}
|
||||
|
||||
return node;
|
||||
|
Loading…
Reference in New Issue
Block a user