Skip to content

Commit

Permalink
Removed support for unclosed entities.
Browse files Browse the repository at this point in the history
  • Loading branch information
bnickel committed Jan 26, 2017
1 parent c4aacb7 commit 00acb59
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
6 changes: 2 additions & 4 deletions Core/Source/NSString+HTML.m
Original file line number Diff line number Diff line change
Expand Up @@ -705,25 +705,23 @@ - (NSString *)stringByReplacingHTMLEntities
{
unsigned long long scannedLongLong;

if ([scanner scanHexLongLong:&scannedLongLong] && scannedLongLong <= UINT32_MAX)
if ([scanner scanHexLongLong:&scannedLongLong] && scannedLongLong <= UINT32_MAX && [scanner scanString:@";" intoString:NULL])
{
UTF32Char inputChar = (UTF32Char)CFSwapInt32HostToLittle((UTF32Char)scannedLongLong);
NSString *string = [[NSString alloc] initWithBytes:&inputChar length:4 encoding:NSUTF32LittleEndianStringEncoding];
[output appendString:string];
[scanner scanString:@";" intoString:NULL];
matched = YES;
}
}
else if ([scanner scanString:@"#" intoString:NULL])
{
unsigned long long scannedLongLong;

if ([scanner scanUnsignedLongLong:&scannedLongLong] && scannedLongLong <= UINT32_MAX)
if ([scanner scanUnsignedLongLong:&scannedLongLong] && scannedLongLong <= UINT32_MAX && [scanner scanString:@";" intoString:NULL])
{
UTF32Char inputChar = (UTF32Char)CFSwapInt32HostToLittle((UTF32Char)scannedLongLong);
NSString *string = [[NSString alloc] initWithBytes:&inputChar length:4 encoding:NSUTF32LittleEndianStringEncoding];
[output appendString:string];
[scanner scanString:@";" intoString:NULL];
matched = YES;
}
}
Expand Down
9 changes: 3 additions & 6 deletions Test/Source/NSStringHTMLTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ - (void)testKnownEntityDecoding
- (void)testUnclosedDecoding
{
NSString *encoded = @"&#128516test";
NSString *expected = @"😄test";
NSString *expected = encoded;

NSString *decoded = [encoded stringByReplacingHTMLEntities];
XCTAssertEqualObjects(decoded, expected, @"String is not properly decoded");
Expand All @@ -54,23 +54,20 @@ - (void)testUnclosedDecoding
- (void)testUnclosedHexDecoding
{
NSString *encoded = @"&#x1F604test";
NSString *expected = @"😄test";
NSString *expected = encoded;

NSString *decoded = [encoded stringByReplacingHTMLEntities];
XCTAssertEqualObjects(decoded, expected, @"String is not properly decoded");
}

/* Not implemented.
- (void)testUnclosedKnownEntityDecoding
{
NSString *encoded = @"&lttest";
NSString *expected = @"<test";
NSString *expected = encoded;

NSString *decoded = [encoded stringByReplacingHTMLEntities];
XCTAssertEqualObjects(decoded, expected, @"String is not properly decoded");
}
*/

- (void)testInvalidDecoding
{
Expand Down

0 comments on commit 00acb59

Please sign in to comment.