+2005-02-21 Darin Adler <darin@apple.com>
+
+ Reviewed by John.
+
+ - fixed <rdar://problem/4016358> don't ever display IDN URLs with characters from "possible Latin look-alike" scripts
+
+ * Misc.subproj/WebNSURLExtras.m:
+ (containsPossibleLatinLookalikes): Added.
+ (-[NSString _web_mapHostNameWithRange:encode:makeString:]): Call containsPossibleLatinLookalikes, and if true,
+ don't decode the host name.
+
2005-02-19 Kevin Decker <kdecker@apple.com>
Reviewed by Chris.
#import <Foundation/NSURL_NSURLExtras.h>
#import <unicode/uidna.h>
+#import <unicode/uscript.h>
typedef void (* StringRangeApplierFunction)(NSString *string, NSRange range, void *context);
return lastChar == '/' && [self _web_hasCaseInsensitivePrefix:@"ftp:"];
}
+static bool containsPossibleLatinLookalikes(const UChar *buffer, int32_t length)
+{
+ int32_t i = 0;
+ while (i < length) {
+ UChar32 c;
+ U16_NEXT(buffer, i, length, c)
+ UErrorCode error = U_ZERO_ERROR;
+ UScriptCode script = uscript_getScript(c, &error);
+ if (error != U_ZERO_ERROR) {
+ ERROR("got ICU error while trying to look at scripts: %d", error);
+ return true;
+ }
+ // According to Deborah Goldsmith and the Unicode Technical committee, these are the
+ // three scripts that contain characters that look like Latin characters. So as a
+ // matter of policy, we don't display host names containing characters from these
+ // scripts in a "nice" way, to protect the user from misleading host names.
+ switch (script) {
+ case USCRIPT_CHEROKEE:
+ case USCRIPT_CYRILLIC:
+ case USCRIPT_GREEK:
+ return true;
+ default:
+ break;
+ }
+ }
+ return false;
+}
+
// Return value of nil means no mapping is necessary.
// If makeString is NO, then return value is either nil or self to indicate mapping is necessary.
// If makeString is YES, then return value is either nil or the mapped string.
if (numCharactersConverted == length && memcmp(sourceBuffer, destinationBuffer, length * sizeof(UChar)) == 0) {
return nil;
}
+ if (!encode && containsPossibleLatinLookalikes(destinationBuffer, numCharactersConverted)) {
+ return nil;
+ }
return makeString ? [NSString stringWithCharacters:destinationBuffer length:numCharactersConverted] : self;
}