jamietre / CsQuery

CsQuery is a complete CSS selector engine, HTML parser, and jQuery port for C# and .NET 4.
Other
1.16k stars 250 forks source link

.Parents() does not work #128

Closed tzehetner closed 10 years ago

tzehetner commented 11 years ago

How to reproduce:

static class Program
{
    static CQ SelectTextNodes(this CQ content)
    {
        return content.Filter(n => n.NodeType == NodeType.TEXT_NODE)
            .Add(content.Select("*").Contents().Filter(n => n.NodeType == NodeType.TEXT_NODE));
    }

    static void Main(string[] args)
    {
        CQ dom = CQ.Create("abc <a href=\"\">def</a> ghi", HtmlParsingMode.Content);
        var textNodes = dom.SelectTextNodes();
        var p = textNodes.Parents();

        //Now p should contain the parent a-element of the "def" text node but it is empty.
    }
}
jamietre commented 11 years ago

Just verified that parents() is supposed to work with text nodes. Will make this fix.

jamietre commented 11 years ago

Note: jQuery seems to behave inconsistently when dealing with text nodes in traversal methods, and per this discussion didn't (doesn't?) have unit test coverage for text node cases. Parent seems to be an exception in that it's agreed that it should work for text nodes. Linking this just for reference if this comes up in the future.

http://bugs.jquery.com/ticket/13265