Merge pull request #2973 from dreampiggy/behavior_uttype_from_unkown_format

Change the behavior to return the abstract type for unknown image format, this  can solve the accident issue for custom coder who provide a new format
This commit is contained in:
DreamPiggy 2020-04-04 16:52:53 +08:00 committed by GitHub
commit 83a40c3679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 3 deletions

View File

@ -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;

View File

@ -119,8 +119,8 @@
UTType = kUTTypeScalableVectorGraphics;
break;
default:
// default is kUTTypePNG
UTType = kUTTypePNG;
// default is kUTTypeImage abstract type
UTType = kUTTypeImage;
break;
}
return UTType;

View File

@ -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);
}