From b7bf9d2b0425daebcf3468abae447d4c725d43dd Mon Sep 17 00:00:00 2001 From: iska Date: Wed, 21 Mar 2018 22:19:24 +0100 Subject: [PATCH] Use HTMLOrderedDictionary when cloning element's attributes --- Sources/HTMLOrderedDictionary.m | 7 +++++++ Sources/include/HTMLDOM.h | 2 ++ Tests/HTMLKitTests/HTMLNodesTests.m | 12 ++++++++++++ 3 files changed, 21 insertions(+) diff --git a/Sources/HTMLOrderedDictionary.m b/Sources/HTMLOrderedDictionary.m index 8cc03e5..b458b40 100644 --- a/Sources/HTMLOrderedDictionary.m +++ b/Sources/HTMLOrderedDictionary.m @@ -154,4 +154,11 @@ return [_keys countByEnumeratingWithState:state objects:buffer count:len]; } +#pragma mark - Copying + +- (id)mutableCopy +{ + return [[HTMLOrderedDictionary alloc] initWithDictionary:self]; +} + @end diff --git a/Sources/include/HTMLDOM.h b/Sources/include/HTMLDOM.h index 567062b..336db72 100644 --- a/Sources/include/HTMLDOM.h +++ b/Sources/include/HTMLDOM.h @@ -24,3 +24,5 @@ #import "HTMLKitDOMExceptions.h" #import "HTMLNamespaces.h" #import "HTMLQuirksMode.h" + +#import "HTMLOrderedDictionary.h" diff --git a/Tests/HTMLKitTests/HTMLNodesTests.m b/Tests/HTMLKitTests/HTMLNodesTests.m index 7461965..94aeda2 100644 --- a/Tests/HTMLKitTests/HTMLNodesTests.m +++ b/Tests/HTMLKitTests/HTMLNodesTests.m @@ -543,6 +543,18 @@ XCTAssertEqualObjects(clone.firstChild.firstChild.asElement.attributes, innerLevel2.attributes); } +- (void)testDeepCloneElementAttributes { + HTMLElement *div = [[HTMLElement alloc] initWithTagName:@"div" + attributes:@{@"id": @"outer", + @"class": @"green", + @"data": @"test"}]; + + HTMLElement *clone = [div cloneNodeDeep:YES]; + + XCTAssertEqualObjects(clone.attributes, div.attributes); + XCTAssertTrue([clone.attributes isKindOfClass:[HTMLOrderedDictionary class]]); +} + #pragma mark - Bug Fixes - (void)testBugFix_Issue_20 {