Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASIWebPageRequest fixes #392

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions Classes/ASIWebPageRequest/ASIWebPageRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,25 @@ - (void)readResourceURLs
}

// Parse the content of <source src=""> tags (HTML 5 audio + video)
// We explictly disable the download of files with .webm, .ogv and .ogg extensions, since it's highly likely they won't be useful to us
} else if ([[parentName lowercaseString] isEqualToString:@"source"] || [[parentName lowercaseString] isEqualToString:@"audio"]) {
// We explictly disable the download of files with extensions .webm,.ogv,.ogg,.mp4,.avi,.mpg,.mpeg and .mkv extensions, since it's highly likely they won't be useful to us
} else if ([[parentName lowercaseString] isEqualToString:@"source"] || [[parentName lowercaseString] isEqualToString:@"audio"] || [[parentName lowercaseString] isEqualToString:@"video"]) {

NSString *fileExtension = [[value pathExtension] lowercaseString];
if (![fileExtension isEqualToString:@"ogg"] && ![fileExtension isEqualToString:@"ogv"] && ![fileExtension isEqualToString:@"webm"]) {

static NSSet *exludedExtensions = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
exludedExtensions = [[NSSet setWithArray:@[ @"ogg"
, @"ogv"
, @"webm"
, @"mp4"
, @"avi"
, @"mpg"
, @"mpeg"
, @"mkv" ]] retain];
});

if ( ![exludedExtensions containsObject:fileExtension] ) {
[self addURLToFetch:value];
}

Expand All @@ -495,6 +510,9 @@ - (void)addURLToFetch:(NSString *)newURL
{
// Get rid of any surrounding whitespace
newURL = [newURL stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
// percent escape characters
newURL = [newURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

// Don't attempt to fetch data URIs
if ([newURL length] > 4) {
if (![[[newURL substringToIndex:5] lowercaseString] isEqualToString:@"data:"]) {
Expand Down Expand Up @@ -676,6 +694,11 @@ - (NSString *)relativePathTo:(NSString *)destinationPath fromPath:(NSString *)so

- (NSString *)contentForExternalURL:(NSString *)theURL
{
// Get rid of any surrounding whitespace
theURL = [theURL stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
// percent escape characters
theURL = [theURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

if ([self urlReplacementMode] == ASIReplaceExternalResourcesWithLocalURLs) {
NSString *resourcePath = [[resourceList objectForKey:theURL] objectForKey:@"DataPath"];
return [self relativePathTo:resourcePath fromPath:[self downloadDestinationPath]];
Expand Down