iabudiab / HTMLKit

An Objective-C framework for your everyday HTML needs.
MIT License
239 stars 27 forks source link

Wrong declaration of a block in the HTMLNodeFilterValue #22

Closed vladvlasov256 closed 6 years ago

vladvlasov256 commented 6 years ago

File HTMLNodeFilter.m:

@interface HTMLNodeFilterBlock ()
{
    BOOL (^ _block)(HTMLNode *);
}
@end

The _block must be an HTMLNodeFilterValue instead of BOOL. Possibly it was a typo.

This issue does nothing on simulators but it leads wrong behavior on devices.

Example:

HTMLDocument *document = [HTMLDocument documentWithString:@"<div id=\"id\"></div>"];

NSString *divId = @"id";
HTMLNodeFilterBlock *filter = [HTMLNodeFilterBlock filterWithBlock:^HTMLNodeFilterValue(HTMLNode * _Nonnull node) {
        HTMLElement *element = (HTMLElement *)node;
        return [element.elementId isEqualToString:divId] ? HTMLNodeFilterAccept : HTMLNodeFilterSkip;
}];

HTMLNodeIterator *iterator = [document nodeIteratorWithShowOptions:HTMLNodeFilterShowElement filter:filter];

HTMLElement *element = (HTMLElement*)iterator.nextObject;

On a simulator, the element is the div. But on a device, the element is the html.

iabudiab commented 6 years ago

@CRivlaldo Nice catch again, thanks for reporting and the PRs