diff options
author | Michael Drake <michael.drake@codethink.co.uk> | 2016-09-01 10:36:23 +0100 |
---|---|---|
committer | Michael Drake <michael.drake@codethink.co.uk> | 2016-09-01 10:41:18 +0100 |
commit | 42bf19d6fe00cb29824b5bc86759183e5a832db6 (patch) | |
tree | aa3bb6e97b28c4504f09ef67098754e226ca12ed /src | |
parent | a1cb751bb8579a9071b255aa3c89abce0394b206 (diff) | |
download | libdom-42bf19d6fe00cb29824b5bc86759183e5a832db6.tar.gz libdom-42bf19d6fe00cb29824b5bc86759183e5a832db6.tar.bz2 |
DOM Document: Fix find by ID, when called with global tree root.
Fixes: NetSurf bug #2466.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/document.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/core/document.c b/src/core/document.c index 14fd1b9..7c0bcdc 100644 --- a/src/core/document.c +++ b/src/core/document.c @@ -1393,23 +1393,23 @@ dom_exception _dom_find_element_by_id(dom_node_internal *root, } if (node->first_child != NULL) { - /* Has children */ + /* Move to child */ node = node->first_child; - } else if (node->next != NULL) { - /* No children, but has siblings */ - node = node->next; } else { - /* No children or siblings. - * Find first unvisited relation. */ - dom_node_internal *parent = node->parent; - - while (parent != root && - node == parent->last_child) { - node = parent; - parent = parent->parent; + while (node != NULL) { + if (node->next != NULL) { + /* Move to next sibling */ + node = node->next; + break; + } else if (node->parent != root) { + /* Move back up to ancestors to + * get to next siblings */ + node = node->parent; + } else { + /* No more nodes below root. */ + node = NULL; + } } - - node = node->next; } } |