ibireme / YYImage

Image framework for iOS to display/encode/decode animated WebP, APNG, GIF, and more.
MIT License
1.77k stars 482 forks source link

In _NSStringPathScale function ,"result.range.location >= 3" should be "result.range.length >= 3". #141

Open tongyuhu opened 5 years ago

tongyuhu commented 5 years ago

static CGFloat _NSStringPathScale(NSString string) { if (string.length == 0 || [string hasSuffix:@"/"]) return 1; NSString name = string.stringByDeletingPathExtension; __block CGFloat scale = 1;

NSRegularExpression *pattern = [NSRegularExpression regularExpressionWithPattern:@"@[0-9]+\\.?[0-9]*x$" options:NSRegularExpressionAnchorsMatchLines error:nil];
[pattern enumerateMatchesInString:name options:kNilOptions range:NSMakeRange(0, name.length) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
    if (result.range.location >= 3) {
        scale = [string substringWithRange:NSMakeRange(result.range.location + 1, result.range.length - 2)].doubleValue;
    }
}];

return scale;

}

return 2 when pass icon@2x.png, but return 1 when pass ic@2x.png. so "result.range.location >= 3" should be "result.range.length >= 3"