Skip to content

find() is completely broken #16

Description

@jpf91

As far as I understand, find is supposed to search only in descendants of the current node. However, find actually searches most nodes in the document:

    auto doc = createDocument("<html>
    <body>
        <div id=\"a1\">
          <div id=\"b1\">
             <div id=\"c1\"></div>
             <div id=\"c2\"></div>
          </div>
          <div id=\"b2\"></div>
        </div>
        <div id=\"a2\"></div>
    </body></html>");
    auto elem = doc.querySelector("#c1");
    writeln(elem.id); //c1
    writeln(elem.find("div")); //[<div id="c1"/>, <div id="c2"/>, <div id="b2"/>, <div id="a2"/>]

To prevent find from scanning ancestors the popFront function in DescendantsDFForward needs to be fixed:

if (parent /*&& (top_ != parent)*/) //FIX in commented code
    next = parent.next_;

However, even with this find will still search siblings (c1 and c2). Is this the expected behaviour? DescendantsDFForward explicitly sets top_ = first.parent_ but I think it'd be more intuitive if find only searched descendants.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions