From 1ce44a12b0558dc1df5111fc1835a1be1c9d6759 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sat, 4 Apr 2020 14:19:08 +0800 Subject: [PATCH] Change the behavior to return the abstract for unknown UTI type, this can solve the accident issue for custom coder who provide a new format --- SDWebImage/Core/NSData+ImageContentType.h | 2 ++ SDWebImage/Core/NSData+ImageContentType.m | 4 ++-- Tests/Tests/SDCategoriesTests.m | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/SDWebImage/Core/NSData+ImageContentType.h b/SDWebImage/Core/NSData+ImageContentType.h index 8c2f97e8..de2a6bf3 100644 --- a/SDWebImage/Core/NSData+ImageContentType.h +++ b/SDWebImage/Core/NSData+ImageContentType.h @@ -45,6 +45,7 @@ static const SDImageFormat SDImageFormatSVG = 8; * * @param format Format as SDImageFormat * @return The UTType as CFStringRef + * @note For unknown format, `kUTTypeImage` abstract type will return */ + (nonnull CFStringRef)sd_UTTypeFromImageFormat:(SDImageFormat)format CF_RETURNS_NOT_RETAINED NS_SWIFT_NAME(sd_UTType(from:)); @@ -53,6 +54,7 @@ static const SDImageFormat SDImageFormatSVG = 8; * * @param uttype The UTType as CFStringRef * @return The Format as SDImageFormat + * @note For unknown type, `SDImageFormatUndefined` will return */ + (SDImageFormat)sd_imageFormatFromUTType:(nonnull CFStringRef)uttype; diff --git a/SDWebImage/Core/NSData+ImageContentType.m b/SDWebImage/Core/NSData+ImageContentType.m index f9014480..87d041ed 100644 --- a/SDWebImage/Core/NSData+ImageContentType.m +++ b/SDWebImage/Core/NSData+ImageContentType.m @@ -119,8 +119,8 @@ UTType = kUTTypeScalableVectorGraphics; break; default: - // default is kUTTypePNG - UTType = kUTTypePNG; + // default is kUTTypeImage abstract type + UTType = kUTTypeImage; break; } return UTType; diff --git a/Tests/Tests/SDCategoriesTests.m b/Tests/Tests/SDCategoriesTests.m index f38fe1bc..ee5aaf56 100644 --- a/Tests/Tests/SDCategoriesTests.m +++ b/Tests/Tests/SDCategoriesTests.m @@ -25,7 +25,7 @@ // Test invalid format CFStringRef type = [NSData sd_UTTypeFromImageFormat:SDImageFormatUndefined]; - expect(CFStringCompare(kUTTypePNG, type, 0)).equal(kCFCompareEqualTo); + expect(CFStringCompare(kUTTypeImage, type, 0)).equal(kCFCompareEqualTo); expect([NSData sd_imageFormatFromUTType:kUTTypeImage]).equal(SDImageFormatUndefined); }