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

This commit is contained in:
DreamPiggy 2020-04-04 14:19:08 +08:00
parent 374b3f7981
commit 1ce44a12b0
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 * @param format Format as SDImageFormat
* @return The UTType as CFStringRef * @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:)); + (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 * @param uttype The UTType as CFStringRef
* @return The Format as SDImageFormat * @return The Format as SDImageFormat
* @note For unknown type, `SDImageFormatUndefined` will return
*/ */
+ (SDImageFormat)sd_imageFormatFromUTType:(nonnull CFStringRef)uttype; + (SDImageFormat)sd_imageFormatFromUTType:(nonnull CFStringRef)uttype;

View File

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

View File

@ -25,7 +25,7 @@
// Test invalid format // Test invalid format
CFStringRef type = [NSData sd_UTTypeFromImageFormat:SDImageFormatUndefined]; 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); expect([NSData sd_imageFormatFromUTType:kUTTypeImage]).equal(SDImageFormatUndefined);
} }