diff --git a/Sources/HTMLElement.m b/Sources/HTMLElement.m index f36bc02..7904e33 100644 --- a/Sources/HTMLElement.m +++ b/Sources/HTMLElement.m @@ -157,11 +157,10 @@ [result appendFormat:@"<%@", self.tagName]; [self.attributes enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) { - NSRange range = NSMakeRange(0, value.length); NSMutableString *escaped = [value mutableCopy]; - [escaped replaceOccurrencesOfString:@"&" withString:@"&" options:0 range:range]; - [escaped replaceOccurrencesOfString:@"\00A0" withString:@" " options:0 range:range]; - [escaped replaceOccurrencesOfString:@"\"" withString:@""" options:0 range:range]; + [escaped replaceOccurrencesOfString:@"&" withString:@"&" options:0 range:NSMakeRange(0, escaped.length)]; + [escaped replaceOccurrencesOfString:@"0x00A0" withString:@" " options:0 range:NSMakeRange(0, escaped.length)]; + [escaped replaceOccurrencesOfString:@"\"" withString:@""" options:0 range:NSMakeRange(0, escaped.length)]; [result appendFormat:@" %@=\"%@\"", key, escaped]; }]; diff --git a/Tests/HTMLKitTests/HTMLSerializationTests.m b/Tests/HTMLKitTests/HTMLSerializationTests.m index 3901bc9..d35087f 100644 --- a/Tests/HTMLKitTests/HTMLSerializationTests.m +++ b/Tests/HTMLKitTests/HTMLSerializationTests.m @@ -33,6 +33,12 @@ XCTAssertEqualObjects(document.body.outerHTML, html); } +- (void)testBugFix_Issue_17 +{ + NSString *html = @""; + HTMLDocument *document = [HTMLDocument documentWithString:html]; + + XCTAssertEqualObjects(document.body.outerHTML, @""); } @end