From e4162bbfc7e3da7c55cd25228eb64f2f2d84a87f Mon Sep 17 00:00:00 2001 From: "stuart.morgan%alumni.case.edu" Date: Sat, 2 Dec 2006 05:14:08 +0000 Subject: [PATCH] Bug 361838: Some valid .url files fail to open. Patch by Wevah . r=max sr=smorgan --- camino/src/extensions/NSURL+Utils.m | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) 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;