iabudiab / HTMLKit

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

NSInvalidArgumentException raised when trying to change an attribute of a cloned element #20

Closed vladvlasov256 closed 6 years ago

vladvlasov256 commented 6 years ago

Impossible to change an attribute of a cloned element if its original element had attributes.

An example:

HTMLElement *element = [HTMLElement new];
element.elementId = @"originalId";

HTMLElement *clone = [element cloneNodeDeep:YES];
NSString *cloneId = @"cloneId";
clone.elementId = cloneId

The last line raises the NSInvalidArgumentException: _[_NSSingleEntryDictionaryI setObject:forKeyedSubscript:]: unrecognized selector sent to instance 0x7fcbd143e150

The root cause is the HTMLElement copy method:

- (id)copyWithZone:(NSZone *)zone
{
    ...
    copy->_attributes = [_attributes copy];
    ...
}

If the _attributes is not nil a copy will be a NSDictionary not a HTMLOrderedDictionary.

iabudiab commented 6 years ago

@CRivlaldo Hey, great catch! Thanks for reporting!