adium 4131:70a376ec444c: Correct a broken UnitTest(!)

commits at adium.im commits at adium.im
Wed Aug 10 03:52:45 UTC 2011


details:	http://hg.adium.im/adium/rev/70a376ec444c
revision:	4131:70a376ec444c
branch:		(none)
author:		Stephen Holt <sholt at adium.im>
date:		Tue Aug 09 19:30:57 2011 -0700

Correct a broken UnitTest(!)

(how long has this been broken?)
Subject: adium 4132:bfe93b6db274: -[NSURL URLWithString:(NSString*)inString] fails creating a link with 2 fragment hashes in the URL.

details:	http://hg.adium.im/adium/rev/bfe93b6db274
revision:	4132:bfe93b6db274
branch:		(none)
author:		Stephen Holt <sholt at adium.im>
date:		Tue Aug 09 20:51:14 2011 -0700

-[NSURL URLWithString:(NSString*)inString] fails creating a link with 2 fragment hashes in the URL.
Filed rdar://9927055

diffs (67 lines):

diff -r ab4789e8a4e7 -r bfe93b6db274 Frameworks/AutoHyperlinks Framework/Source/AHLinkLexer.l
--- a/Frameworks/AutoHyperlinks Framework/Source/AHLinkLexer.l	Tue Aug 09 21:43:12 2011 +0200
+++ b/Frameworks/AutoHyperlinks Framework/Source/AHLinkLexer.l	Tue Aug 09 20:51:14 2011 -0700
@@ -74,7 +74,7 @@
 userAtDomain	[^:@\/[:space:]]+\@{singleDomain}(\.{singleDomain})*
 mailSpec        {userAtDomain}\.{TLDs}
 
-%option noyywrap nounput 8bit caseless never-interactive reentrant warn prefix="AH"
+%option noyywrap nounput noinput 8bit caseless never-interactive reentrant warn prefix="AH"
 
 %x CANONICAL TENTATIVE
 %%
diff -r ab4789e8a4e7 -r bfe93b6db274 Frameworks/AutoHyperlinks Framework/Source/AHMarkedHyperlink.m
--- a/Frameworks/AutoHyperlinks Framework/Source/AHMarkedHyperlink.m	Tue Aug 09 21:43:12 2011 +0200
+++ b/Frameworks/AutoHyperlinks Framework/Source/AHMarkedHyperlink.m	Tue Aug 09 20:51:14 2011 -0700
@@ -97,8 +97,29 @@
 																	 (CFStringRef)@"#[]",
 																	 NULL,
 																	 kCFStringEncodingUTF8);
-	
 	self.URL = [NSURL URLWithString:linkString];
+	// Because -[NSURL URLWithString:(NSString*)inString] fails creating a link with 2 fragment hashes, but we don't want to escape the first one, we esape all '#' to "%23" then unescape the first back to '#'.  rdar://9927055
+	if(!self.URL) {
+		[preString release]; preString = nil;
+		preString = (NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, 
+																						(CFStringRef)preString, 
+																						CFSTR(""), 
+																						kCFStringEncodingUTF8);
+		[linkString release]; linkString = nil;
+		linkString = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
+																		 preString? (CFStringRef)preString : (CFStringRef)inString,
+																		 (CFStringRef)@"[]",
+																		 NULL,
+																		 kCFStringEncodingUTF8);
+		NSRange fragmentRange = [linkString rangeOfString:@"%23"];
+		NSMutableString *mutaLinkString = nil;
+		if (fragmentRange.location != NSNotFound) {
+			mutaLinkString = [linkString mutableCopy];
+			[mutaLinkString replaceOccurrencesOfString:@"%23" withString:@"#" options:0 range:fragmentRange];
+		}
+		self.URL = [NSURL URLWithString:mutaLinkString];
+		[mutaLinkString release];
+	}
 	
 	[linkString release];
 	if(preString) [preString release];
diff -r ab4789e8a4e7 -r bfe93b6db274 Frameworks/AutoHyperlinks Framework/UnitTests/HyperlinkContextTest.m
--- a/Frameworks/AutoHyperlinks Framework/UnitTests/HyperlinkContextTest.m	Tue Aug 09 21:43:12 2011 +0200
+++ b/Frameworks/AutoHyperlinks Framework/UnitTests/HyperlinkContextTest.m	Tue Aug 09 20:51:14 2011 -0700
@@ -13,7 +13,7 @@
 	AHHyperlinkScanner	*scanner = [AHHyperlinkScanner hyperlinkScannerWithString:testString];
 	AHMarkedHyperlink	*ahLink = [scanner nextURI];
 	
-	STAssertNotNil(ahLink, @"-[SHHyperlinkScanner nextURL] found no URI in \"%@\"", testString);
+	STAssertNotNil(ahLink.URL, @"-[SHHyperlinkScanner nextURL] found no URI in \"%@\"", testString);
 	STAssertEqualObjects([[ahLink parentString] substringWithRange:[ahLink range]], URIString, @"in context: '%@'", testString);
 }
 
@@ -216,6 +216,8 @@
 	[self testLaxContext:@"@%@" withURI:@"example.com"];
 	
 	[self testLaxContext:@"foo (bar) %@" withURI:@"http://example.com/path/to/url.html"];
+	
+	[self testLaxContext:@"%@ doesn't link." withURI:@"http://developer.apple.com/library/iOS/#documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html#//apple_ref/doc/uid/TP40002974-CH4-SW3"];
 }
 
 - (void)testCompositeContext {




More information about the commits mailing list