Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixes issue #221 #222

Merged
merged 1 commit into from

2 participants

@thillerson

If img src is nil, don't attempt to do anything with the src.

@thillerson

Fixes issue: #221

@Cocoanetics Cocoanetics merged commit 1000f0b into Cocoanetics:master
@Cocoanetics
Owner

Good job! Note: if you write hash and number by itself then it references the original issue with a link. If you write fixes #221 then you also close the issue automatically.

@thillerson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 15, 2012
  1. @thillerson
This page is out of date. Refresh to see the latest.
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];
+ }
}
}
}
Something went wrong with that request. Please try again.