aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2014-11-20 13:02:53 +0100
committerNick Wellnhofer <wellnhofer@aevum.de>2014-11-22 16:08:32 +0100
commit759e03748a368be8b209dfd113441c05e1a5dcc0 (patch)
tree34147fb5ac44a69c1523f79d9346d4f76cb59802 /src
parentcf1c490c7a3fd3f9681e97f1e662735e1509250c (diff)
More tree hierarchy checks and tests
Diffstat (limited to 'src')
-rw-r--r--src/node.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/node.c b/src/node.c
index 624baad..4317dd4 100644
--- a/src/node.c
+++ b/src/node.c
@@ -348,6 +348,17 @@ S_is_inline(cmark_node *node) {
static bool
S_can_contain(cmark_node *node, cmark_node *child)
{
+ cmark_node *cur;
+
+ // Verify that child is not an ancestor of node or equal to node.
+ cur = node;
+ do {
+ if (cur == child) {
+ return false;
+ }
+ cur = cur->parent;
+ } while (cur != NULL);
+
if (child->type == CMARK_NODE_DOCUMENT) {
return false;
}