Reputation: 121
I've had an iPhone app in the store for 2 years that loaded local HTML files into a webview. While updating it I've run into an issue with the file paths. One of the elements in the path is in Russian, which still looks fine in _finalPath
, but when I wrap it in an NSURL, the Cyrillic letters are converted to Unicode entities, breaking the path to the HTML file.
//finalPath is figured in and passed on from tenseListViewController
//ACK - this now seems to turn брать into %D0%B1%D1%80%D0%B0%D1%82%D1%8C in the middle of the path!
NSLog(@"-->starting showInfo: _finalPath is %@", _finalPath);
NSURL *url = [NSURL fileURLWithPath:_finalPath];
NSLog(@"*url is %@", url);
Here's the output in the log:
2013-06-05 13:51:39.409 NewTryout[29609:c07] -->starting showInfo: _finalPath is /Users/cford/Library/Application Support/iPhone Simulator/6.1/Applications/8C06E53D-BFA6-4EA5-823A-0EBDBB3B51B2/NewTryout.app/verbs/брать/imperfective/Present.html
2013-06-05 13:51:39.409 NewTryout[29609:c07] *url is file://localhost/Users/cford/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/8C06E53D-BFA6-4EA5-823A-0EBDBB3B51B2/NewTryout.app/verbs/%D0%B1%D1%80%D0%B0%D1%82%D1%8C/imperfective/Present.html
Is this a change in iOS5 or 6, or should I be looking at something else in my code? Any suggestions?
Upvotes: 2
Views: 353
Reputation: 595349
Non-ASCII characters are simply not allowed in URLs to begin with (IRIs were invented to replace URLs, in particular to support Unicode). Your Russian characters are being encoded to UTF-8 octets and then those octets are being URL-encoded. That is correct behavior for URLs, and works just fine in HTML links. If the WebView is not opening the HTML file correctly when the link is clicked, then the WebView itself must be broken when processing URLs. It should be URL-decoding and UTF8-decoding the data before then using it. If it is not, then that is a bug in the WebView. Unless the WebView is just giving you the raw URL text when the link is clicked, and you are opening the file yourself, in which case it is your responsibility to decode the URL data before then using it in the rest of your code.
Upvotes: 2