NSURL cannot handle Unicode strings

Originator:craig.hockenberry
Number:rdar://6923460 Date Originated:
Status:Closed Resolved:
Product:Mac OS X Product Version:10.5.7
Classification:Serious Bug Reproducible:Always
 
Summary: 
URLs that contain Unicode characters are not handled correctly by NSURL.

Steps to Reproduce:
1) Open the attached project.
2) Click on the "Open Unicode Domain" button.

Expected Results:
The URL should open in the user's browser.

Actual Results:
The NSURL instance returned by [NSURL URLWithString:@"http://✪df.ws/d61"] is nil.

Regression:
This is a problem on both Mac and iPhone.

Notes:
If the domain name is decoded according to RFC 3492, the NSURL instance returned is valid and can be used to open a URL.

The sample project is located here: http://files.iconfactory.net/craig/bugs/UnicodeURL.zip

Comments

RTFM

Upon further RTFM, adding percent escapes to the URL string conform to RFC 2396 allows openURL to convert the Unicode to punycode. For example:

NSString *test = @"http://✪df.ws/d61"; // OK

NSString URLString = [(NSString ) CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef) test, CFSTR(""), NULL, kCFStringEncodingUTF8) autorelease];

NSURL *URL = [NSURL URLWithString:URLString];

By craig.hockenberry at May 27, 2009, 7:21 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!