Skip to content

Commit 8546168

Browse files
committedMar 21, 2018
Merge branch 'release/2.1.3'
2 parents 682b19c + ec6d03e commit 8546168

11 files changed

+99
-6
lines changed
 

‎.jazzy.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module: HTMLKit
2-
module_version: 2.1.2
2+
module_version: 2.1.3
33
author: Iskandar Abudiab
44
author_url: https://twitter.com/iabudiab
55
github_url: https://github.com/iabudiab/HTMLKit

‎CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Change Log
22

3+
## [2.1.3](https://github.com/iabudiab/HTMLKit/releases/tag/2.1.3)
4+
5+
Released on 2018.03.21
6+
7+
### Fixes
8+
9+
- `HTMLElement` clone would return an immutable dictionary for attributes (issue #20)
10+
- Fixed by @CRivlaldo in PR #24
11+
- `HTMLNodeFilterBlock` would behave differently on simulator and device (issue #22)
12+
- Fixed by @CRivlaldo in PR #23
13+
14+
315
## [2.1.2](https://github.com/iabudiab/HTMLKit/releases/tag/2.1.2)
416

517
Released on 2017.11.6

‎HTMLKit.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "HTMLKit"
3-
s.version = "2.1.2"
3+
s.version = "2.1.3"
44
s.summary = "HTMLKit, an Objective-C framework for your everyday HTML needs."
55
s.license = "MIT"
66
s.homepage = "https://github.com/iabudiab/HTMLKit"

‎Sources/HTMLElement.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ - (id)copyWithZone:(NSZone *)zone
144144
{
145145
HTMLElement *copy = [super copyWithZone:zone];
146146
copy->_tagName = [_tagName copy];
147-
copy->_attributes = [_attributes copy];
147+
copy->_attributes = [_attributes mutableCopy];
148148
copy->_htmlNamespace = _htmlNamespace;
149149
return copy;
150150
}

‎Sources/HTMLKit-Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundlePackageType</key>
1818
<string>FMWK</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>2.1.2</string>
20+
<string>2.1.3</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>

‎Sources/HTMLNodeFilter.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
@interface HTMLNodeFilterBlock ()
1717
{
18-
BOOL (^ _block)(HTMLNode *);
18+
HTMLNodeFilterValue (^ _block)(HTMLNode *);
1919
}
2020
@end
2121

‎Sources/HTMLOrderedDictionary.m

+7
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,11 @@ - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state object
154154
return [_keys countByEnumeratingWithState:state objects:buffer count:len];
155155
}
156156

157+
#pragma mark - Copying
158+
159+
- (id)mutableCopy
160+
{
161+
return [[HTMLOrderedDictionary alloc] initWithDictionary:self];
162+
}
163+
157164
@end

‎Sources/include/HTMLDOM.h

+2
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@
2424
#import "HTMLKitDOMExceptions.h"
2525
#import "HTMLNamespaces.h"
2626
#import "HTMLQuirksMode.h"
27+
28+
#import "HTMLOrderedDictionary.h"

‎Tests/HTMLKitTests/HTMLNodeIteratorTests.m

+16
Original file line numberDiff line numberDiff line change
@@ -592,4 +592,20 @@ - (void)testBugFix_Issue_4
592592
XCTAssertEqual(0, nodeIterators.count);
593593
}
594594

595+
- (void)testBugFix_Issue_22 {
596+
// The issue is applicable only for devices. On simulator the test is passed.
597+
HTMLDocument *document = [HTMLDocument documentWithString:@"<div id=\"id\"></div>"];
598+
599+
NSString *divId = @"id";
600+
HTMLNodeFilterBlock *filter = [HTMLNodeFilterBlock filterWithBlock:^HTMLNodeFilterValue(HTMLNode * _Nonnull node) {
601+
HTMLElement *element = (HTMLElement *)node;
602+
return [element.elementId isEqualToString:divId] ? HTMLNodeFilterAccept : HTMLNodeFilterSkip;
603+
}];
604+
605+
HTMLNodeIterator *iterator = [document nodeIteratorWithShowOptions:HTMLNodeFilterShowElement filter:filter];
606+
607+
HTMLElement *element = (HTMLElement*)iterator.nextObject;
608+
XCTAssertTrue([element.elementId isEqualToString:divId]);
609+
}
610+
595611
@end

‎Tests/HTMLKitTests/HTMLNodesTests.m

+56
Original file line numberDiff line numberDiff line change
@@ -512,4 +512,60 @@ - (void)testCompareDocumentPosition
512512
XCTAssertTrue([image compareDocumentPositionWithNode:outerDiv] == (HTMLDocumentPositionContainedBy | HTMLDocumentPositionFollowing));
513513
}
514514

515+
- (void)testDeepCloneElement {
516+
HTMLElement *outer = [[HTMLElement alloc] initWithTagName:@"div"
517+
attributes:@{@"id": @"outer",
518+
@"class": @"green"}];
519+
520+
HTMLElement *innerLevel1 = [[HTMLElement alloc] initWithTagName:@"div"
521+
attributes:@{@"id": @"inner1",
522+
@"class": @"red"}];
523+
524+
HTMLElement *innerLevel2 = [[HTMLElement alloc] initWithTagName:@"div"
525+
attributes:@{@"id": @"inner2",
526+
@"class": @"red"}];
527+
528+
[outer appendNode:innerLevel1];
529+
[innerLevel1 appendNode:innerLevel2];
530+
531+
HTMLElement *clone = [outer cloneNodeDeep:YES];
532+
533+
XCTAssertNotEqual(clone, outer);
534+
XCTAssertEqualObjects(clone.elementId, outer.elementId);
535+
XCTAssertEqualObjects(clone.attributes, outer.attributes);
536+
537+
XCTAssertNotEqual(clone.firstChild, innerLevel1);
538+
XCTAssertEqualObjects(clone.firstChild.asElement.elementId, innerLevel1.elementId);
539+
XCTAssertEqualObjects(clone.firstChild.asElement.attributes, innerLevel1.attributes);
540+
541+
XCTAssertNotEqual(clone.firstChild, innerLevel2);
542+
XCTAssertEqualObjects(clone.firstChild.firstChild.asElement.elementId, innerLevel2.elementId);
543+
XCTAssertEqualObjects(clone.firstChild.firstChild.asElement.attributes, innerLevel2.attributes);
544+
}
545+
546+
- (void)testDeepCloneElementAttributes {
547+
HTMLElement *div = [[HTMLElement alloc] initWithTagName:@"div"
548+
attributes:@{@"id": @"outer",
549+
@"class": @"green",
550+
@"data": @"test"}];
551+
552+
HTMLElement *clone = [div cloneNodeDeep:YES];
553+
554+
XCTAssertEqualObjects(clone.attributes, div.attributes);
555+
XCTAssertTrue([clone.attributes isKindOfClass:[HTMLOrderedDictionary class]]);
556+
}
557+
558+
#pragma mark - Bug Fixes
559+
560+
- (void)testBugFix_Issue_20 {
561+
HTMLElement *element = [HTMLElement new];
562+
element.elementId = @"originalId";
563+
564+
HTMLElement *clone = [element cloneNodeDeep:YES];
565+
NSString *cloneId = @"cloneId";
566+
clone.elementId = cloneId;
567+
568+
XCTAssertTrue([clone.elementId isEqualToString:cloneId]);
569+
}
570+
515571
@end

0 commit comments

Comments
 (0)
Please sign in to comment.