react-native-fast-image 8.27.2 → 8.27.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -157,18 +157,73 @@ static CGSize FFFPhotoPixelSize(NSURL *url)
|
|
|
157
157
|
// body is an image: a page sent instead (e.g. a captive portal's, with status
|
|
158
158
|
// 200) would be served from there until it expired, and each load would fail.
|
|
159
159
|
// Removing it after a load failed (forgetResponseAfterError:) could still be
|
|
160
|
-
// in progress when the next load started.
|
|
160
|
+
// in progress when the next load started. A page with an inline <svg> isn't
|
|
161
|
+
// an SVG image.
|
|
161
162
|
@interface FFFWebDownloaderOperation : SDWebImageDownloaderOperation
|
|
162
163
|
@end
|
|
163
164
|
|
|
164
165
|
@implementation FFFWebDownloaderOperation
|
|
165
166
|
|
|
167
|
+
// Whether data is an SVG document: its first element (after an XML
|
|
168
|
+
// declaration, comments or a doctype) is <svg>, as on Android
|
|
169
|
+
// (FastImageSvg.looksLikeSvg). SDWebImage takes data that starts with '<' and
|
|
170
|
+
// has an <svg> element anywhere for SVG, such as a page with an icon.
|
|
171
|
+
static BOOL FFFHasPrefixAt(NSString *text, NSUInteger i, NSString *prefix)
|
|
172
|
+
{
|
|
173
|
+
return text.length - i >= prefix.length && [text compare:prefix options:0 range:NSMakeRange(i, prefix.length)] == NSOrderedSame;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// The index after the end marker from i, or NSNotFound if it isn't there.
|
|
177
|
+
static NSUInteger FFFSkipPast(NSString *text, NSUInteger i, NSString *end)
|
|
178
|
+
{
|
|
179
|
+
NSRange found = [text rangeOfString:end options:0 range:NSMakeRange(i, text.length - i)];
|
|
180
|
+
return found.location == NSNotFound ? NSNotFound : NSMaxRange(found);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
static BOOL FFFLooksLikeSVG(NSData *data)
|
|
184
|
+
{
|
|
185
|
+
// The markup is ASCII: Latin-1 reads any bytes (a UTF-8 character cut off
|
|
186
|
+
// at the end too).
|
|
187
|
+
NSData *head = [data subdataWithRange:NSMakeRange(0, MIN(data.length, (NSUInteger)1024))];
|
|
188
|
+
NSString *text = [[[NSString alloc] initWithData:head encoding:NSISOLatin1StringEncoding] lowercaseString];
|
|
189
|
+
NSCharacterSet *space = NSCharacterSet.whitespaceAndNewlineCharacterSet;
|
|
190
|
+
// A UTF-8 byte order mark, as Latin-1.
|
|
191
|
+
NSUInteger i = FFFHasPrefixAt(text, 0, @"\u00EF\u00BB\u00BF") ? 3 : 0;
|
|
192
|
+
while (i < text.length) {
|
|
193
|
+
if ([space characterIsMember:[text characterAtIndex:i]]) {
|
|
194
|
+
i++;
|
|
195
|
+
} else if (FFFHasPrefixAt(text, i, @"<?")) {
|
|
196
|
+
i = FFFSkipPast(text, i, @"?>");
|
|
197
|
+
} else if (FFFHasPrefixAt(text, i, @"<!--")) {
|
|
198
|
+
i = FFFSkipPast(text, i, @"-->");
|
|
199
|
+
} else if (FFFHasPrefixAt(text, i, @"<!")) {
|
|
200
|
+
// A doctype, whose internal subset ([...]) can have '>'s.
|
|
201
|
+
NSRange rest = NSMakeRange(i, text.length - i);
|
|
202
|
+
NSUInteger subset = [text rangeOfString:@"[" options:0 range:rest].location;
|
|
203
|
+
NSUInteger close = [text rangeOfString:@">" options:0 range:rest].location;
|
|
204
|
+
if (subset != NSNotFound && subset < close) {
|
|
205
|
+
i = FFFSkipPast(text, subset, @"]");
|
|
206
|
+
}
|
|
207
|
+
if (i != NSNotFound) {
|
|
208
|
+
i = FFFSkipPast(text, i, @">");
|
|
209
|
+
}
|
|
210
|
+
} else {
|
|
211
|
+
return FFFHasPrefixAt(text, i, @"<svg");
|
|
212
|
+
}
|
|
213
|
+
if (i == NSNotFound) {
|
|
214
|
+
return NO;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return NO;
|
|
218
|
+
}
|
|
219
|
+
|
|
166
220
|
- (void)URLSession:(NSURLSession *)session
|
|
167
221
|
dataTask:(NSURLSessionDataTask *)dataTask
|
|
168
222
|
willCacheResponse:(NSCachedURLResponse *)proposedResponse
|
|
169
223
|
completionHandler:(void (^)(NSCachedURLResponse *cachedResponse))completionHandler
|
|
170
224
|
{
|
|
171
|
-
|
|
225
|
+
SDImageFormat format = [NSData sd_imageFormatForImageData:proposedResponse.data];
|
|
226
|
+
if (format == SDImageFormatUndefined || (format == SDImageFormatSVG && !FFFLooksLikeSVG(proposedResponse.data))) {
|
|
172
227
|
completionHandler(nil);
|
|
173
228
|
return;
|
|
174
229
|
}
|