зеркало из https://github.com/mozilla/pjs.git
Bug 361838: Some valid .url files fail to open. Patch by Wevah <mozilla@derailer.org>. r=max sr=smorgan
This commit is contained in:
Родитель
9b8201d02d
Коммит
e6c1c2199c
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче