Title: [239970] trunk/Source/WTF
- Revision
- 239970
- Author
- [email protected]
- Date
- 2019-01-14 19:26:04 -0800 (Mon, 14 Jan 2019)
Log Message
Use unorm2_normalize instead of precomposedStringWithCanonicalMapping in userVisibleString
https://bugs.webkit.org/show_bug.cgi?id=192945
Reviewed by Alex Christensen.
Replace use of the nice NSString function precomposedStringWithCanonicalMapping with the ICU
API unorm2_normalize. This is to prep the code for translation to cross-platform C++. Of
course this is much worse than the preexisting code, but this is just a transitional
measure and not the final state of the code. It wouldn't make sense to do this if the code
were to remain Objective C++.
* wtf/cocoa/NSURLExtras.mm:
(WTF::toNormalizationFormC):
(WTF::userVisibleString):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (239969 => 239970)
--- trunk/Source/WTF/ChangeLog 2019-01-15 03:01:31 UTC (rev 239969)
+++ trunk/Source/WTF/ChangeLog 2019-01-15 03:26:04 UTC (rev 239970)
@@ -1,3 +1,20 @@
+2019-01-14 Michael Catanzaro <[email protected]>
+
+ Use unorm2_normalize instead of precomposedStringWithCanonicalMapping in userVisibleString
+ https://bugs.webkit.org/show_bug.cgi?id=192945
+
+ Reviewed by Alex Christensen.
+
+ Replace use of the nice NSString function precomposedStringWithCanonicalMapping with the ICU
+ API unorm2_normalize. This is to prep the code for translation to cross-platform C++. Of
+ course this is much worse than the preexisting code, but this is just a transitional
+ measure and not the final state of the code. It wouldn't make sense to do this if the code
+ were to remain Objective C++.
+
+ * wtf/cocoa/NSURLExtras.mm:
+ (WTF::toNormalizationFormC):
+ (WTF::userVisibleString):
+
2019-01-14 Alex Christensen <[email protected]>
Bulgarian TLD should not punycode-encode URLs with Bulgarian Cyrillic characters
Modified: trunk/Source/WTF/wtf/cocoa/NSURLExtras.mm (239969 => 239970)
--- trunk/Source/WTF/wtf/cocoa/NSURLExtras.mm 2019-01-15 03:01:31 UTC (rev 239969)
+++ trunk/Source/WTF/wtf/cocoa/NSURLExtras.mm 2019-01-15 03:26:04 UTC (rev 239970)
@@ -32,6 +32,7 @@
#import <unicode/uchar.h>
#import <unicode/uidna.h>
+#import <unicode/unorm.h>
#import <unicode/uscript.h>
#import <wtf/Function.h>
#import <wtf/HexNumber.h>
@@ -1105,6 +1106,31 @@
return CFStringCreateWithCharacters(nullptr, outBuffer.data(), outBuffer.size());
}
+static String toNormalizationFormC(const String& string)
+{
+ auto sourceBuffer = string.charactersWithNullTermination();
+ ASSERT(sourceBuffer.last() == '\0');
+ sourceBuffer.removeLast();
+
+ String result;
+ Vector<UChar, URL_BYTES_BUFFER_LENGTH> normalizedCharacters(sourceBuffer.size());
+ UErrorCode uerror = U_ZERO_ERROR;
+ int32_t normalizedLength = 0;
+ const UNormalizer2 *normalizer = unorm2_getNFCInstance(&uerror);
+ if (!U_FAILURE(uerror)) {
+ normalizedLength = unorm2_normalize(normalizer, sourceBuffer.data(), sourceBuffer.size(), normalizedCharacters.data(), normalizedCharacters.size(), &uerror);
+ if (uerror == U_BUFFER_OVERFLOW_ERROR) {
+ uerror = U_ZERO_ERROR;
+ normalizedCharacters.resize(normalizedLength);
+ normalizedLength = unorm2_normalize(normalizer, sourceBuffer.data(), sourceBuffer.size(), normalizedCharacters.data(), normalizedLength, &uerror);
+ }
+ if (!U_FAILURE(uerror))
+ result = String(normalizedCharacters.data(), normalizedLength);
+ }
+
+ return result;
+}
+
NSString *userVisibleString(NSURL *URL)
{
NSData *data = ""
@@ -1175,7 +1201,9 @@
result = mappedResult;
}
- result = [result precomposedStringWithCanonicalMapping];
+ auto wtfString = String(result.get());
+ auto normalized = toNormalizationFormC(wtfString);
+ result = static_cast<NSString *>(normalized);
return CFBridgingRelease(createStringWithEscapedUnsafeCharacters((__bridge CFStringRef)result.get()));
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes