Navigation Menu

Skip to content

Commit

Permalink
Guard against images with no src causing strange issues with image
Browse files Browse the repository at this point in the history
attachments
  • Loading branch information
thillerson committed Sep 15, 2012
1 parent 131fe2b commit 0eedfdd
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions Core/Source/DTTextAttachment.m
Expand Up @@ -78,41 +78,43 @@ + (DTTextAttachment *)textAttachmentWithElement:(DTHTMLElement *)element options


// decode content URL
if ([src hasPrefix:@"data:"])
{
NSRange range = [src rangeOfString:@"base64,"];

if (range.length)
if (src != nil) { // guard against img with no src
if ([src hasPrefix:@"data:"])
{
NSString *encodedData = [src substringFromIndex:range.location + range.length];
NSData *decodedData = [NSData dataFromBase64String:encodedData];

decodedImage = [[DTImage alloc] initWithData:decodedData];
NSRange range = [src rangeOfString:@"base64,"];

if (!displaySize.width || !displaySize.height)
if (range.length)
{
displaySize = decodedImage.size;
NSString *encodedData = [src substringFromIndex:range.location + range.length];
NSData *decodedData = [NSData dataFromBase64String:encodedData];

decodedImage = [[DTImage alloc] initWithData:decodedData];

if (!displaySize.width || !displaySize.height)
{
displaySize = decodedImage.size;
}
}
}
}
else // normal URL
{
contentURL = [NSURL URLWithString:src];

if (![contentURL scheme])
else // normal URL
{
// possibly a relative url
if (baseURL)
{
contentURL = [NSURL URLWithString:src relativeToURL:baseURL];
}
else
contentURL = [NSURL URLWithString:src];

if (![contentURL scheme])
{
// file in app bundle
NSString *path = [[NSBundle mainBundle] pathForResource:src ofType:nil];
if (path) {
// Prevent a crash if path turns up nil.
contentURL = [NSURL fileURLWithPath:path];
// possibly a relative url
if (baseURL)
{
contentURL = [NSURL URLWithString:src relativeToURL:baseURL];
}
else
{
// file in app bundle
NSString *path = [[NSBundle mainBundle] pathForResource:src ofType:nil];
if (path) {
// Prevent a crash if path turns up nil.
contentURL = [NSURL fileURLWithPath:path];
}
}
}
}
Expand Down

0 comments on commit 0eedfdd

Please sign in to comment.