Skip to content

Commit

Permalink
Make isSVGFormatForData work for small SVG strings
Browse files Browse the repository at this point in the history
The current `isSVGFormatForData` breaks when the SVG is less than 100 characters, which should be permitted (e.g., "`<svg><circle/></svg>`" is valid SVG).
  • Loading branch information
marcprux authored Aug 13, 2020
1 parent 1befe3d commit 7127ab3
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions SDWebImageSVGCoder/Classes/SDImageSVGCoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,8 @@ + (BOOL)isSVGFormatForData:(NSData *)data {
if (!data) {
return NO;
}
if (data.length <= 100) {
return NO;
}
// Check end with SVG tag
NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(data.length - 100, 100)] encoding:NSASCIIStringEncoding];
if (![testString containsString:kSVGTagEnd]) {
return NO;
}
return YES;

return [data rangeOfData:[kSVGTagEnd dataUsingEncoding:NSUTF8StringEncoding] options:NSDataSearchBackwards range: NSMakeRange(data.length - MIN(100, data.length), MIN(100, data.length))].location != NSNotFound;
}

@end

0 comments on commit 7127ab3

Please sign in to comment.