Bug 361838: Some valid .url files fail to open. Patch by Wevah <mozilla@derailer.org>. r=max sr=smorgan

This commit is contained in:
stuart.morgan%alumni.case.edu 2006-12-02 05:14:08 +00:00
Родитель 3cd18026cf
Коммит e4162bbfc7
1 изменённых файлов: 18 добавлений и 5 удалений

Просмотреть файл

@ -44,6 +44,7 @@
//
// Reads the URL from a .webloc/.ftploc file.
// Returns the URL, or nil on failure.
//
+(NSURL*)URLFromInetloc:(NSString*)inFile
{
FSRef ref;
@ -91,12 +92,24 @@
if (inFile) {
NSCharacterSet *newlines = [NSCharacterSet characterSetWithCharactersInString:@"\r\n"];
NSScanner *scanner = [NSScanner scannerWithString:[NSString stringWithContentsOfFile:inFile]];
NSString *urlString;
[scanner scanUpToString:@"[InternetShortcut]" intoString:nil];
if ([scanner scanString:@"[InternetShortcut]" intoString:nil] &&
[scanner scanString:@"URL=" intoString:nil] &&
[scanner scanUpToCharactersFromSet:newlines intoString:&urlString])
ret = [NSURL URLWithString:urlString];
if ([scanner scanString:@"[InternetShortcut]" intoString:nil]) {
// Scan each non-empty line in this section. We don't need to explicitly scan the newlines or
// whitespace because NSScanner ignores these by default.
NSString *line;
while ([scanner scanUpToCharactersFromSet:newlines intoString:&line]) {
if ([line hasPrefix:@"URL="]) {
ret = [NSURL URLWithString:[line substringFromIndex:4]];
break;
}
else if ([line hasPrefix:@"["]) {
// This is the start of a new section, so if we haven't found an URL yet, we should bail.
break;
}
}
}
}
return ret;