[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XmlElement.GetChildrenByFilter not selecting correct child


On 5/11/25 2:37 PM, Lee wrote:
I am trying to get the <tbody> element of a table. But .GetChildrenByFilter("table > tbody") selects the <thead> element instead. That same CSS selector tested with two different online testers works as expected, so I think it is correct. But, I could be wrong.

Is this a bug?

Demo project attached.



After looking at the relevant code at lines 21-28 of cssfilter.cpp [1]
[C-code]
    pos = (char*)memrchr(filter, '>', lenFilter);
    if(pos)
    {
        Element *parent = (Element*)(elmt->parent);
        if(!parent) return false;
        return HTMLElement_MatchFilter(parent, filter, (pos - filter))  &&
                HTMLElement_MatchFilter(elmt, pos, lenFilter - (pos + 1 - filter));
    }

[/C-code]

and deciphering how one could get an integer by subtracting one string (character array) from another (LOL, it's actually pointer arithmetic), I can't find anything wrong with it. It should work as expected.

Mimicking that logic as nearly but simply as possible in Gambas code does indeed work as expected. I'm lost.


[1] https://gitlab.com/gambas/gambas/-/blob/master/gb.xml/src/html/cssfilter.cpp


--
Lee

--- Gambas User List Netiquette [https://gambaswiki.org/wiki/doc/netiquette] ----
--- Gambas User List Archive [https://lists.gambas-basic.org/archive/user] ----


References:
XmlElement.GetChildrenByFilter not selecting correct childLee <t.lee.davidson@xxxxxxxxx>