diff --git a/camino/src/extensions/NSURL+Utils.m b/camino/src/extensions/NSURL+Utils.m index c25cf34b95f8..19abfee481d4 100644 --- a/camino/src/extensions/NSURL+Utils.m +++ b/camino/src/extensions/NSURL+Utils.m @@ -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;