Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Guard against images with no src causing strange issues with image

attachments
  • Loading branch information...
commit 0eedfdd57ae16f31dd578de18e316f66ba4ac4ec 1 parent 131fe2b
@thillerson thillerson authored
Showing with 30 additions and 28 deletions.
  1. +30 −28 Core/Source/DTTextAttachment.m
View
58 Core/Source/DTTextAttachment.m
@@ -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];
+ }
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.