Title: [242545] releases/WebKitGTK/webkit-2.24/Source/WTF
Revision
242545
Author
[email protected]
Date
2019-03-06 05:30:45 -0800 (Wed, 06 Mar 2019)

Log Message

Merge r242353 - URLHelpers should use unorm2_quickCheck before converting to NFC
https://bugs.webkit.org/show_bug.cgi?id=194272

Reviewed by Darin Adler.

If the string is already in normalization form C, don't try to normalize it.

* wtf/URLHelpers.cpp:
(WTF::URLHelpers::toNormalizationFormC):

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.24/Source/WTF/ChangeLog (242544 => 242545)


--- releases/WebKitGTK/webkit-2.24/Source/WTF/ChangeLog	2019-03-06 13:30:42 UTC (rev 242544)
+++ releases/WebKitGTK/webkit-2.24/Source/WTF/ChangeLog	2019-03-06 13:30:45 UTC (rev 242545)
@@ -1,3 +1,15 @@
+2019-03-04  Michael Catanzaro  <[email protected]>
+
+        URLHelpers should use unorm2_quickCheck before converting to NFC
+        https://bugs.webkit.org/show_bug.cgi?id=194272
+
+        Reviewed by Darin Adler.
+
+        If the string is already in normalization form C, don't try to normalize it.
+
+        * wtf/URLHelpers.cpp:
+        (WTF::URLHelpers::toNormalizationFormC):
+
 2019-03-02  Darin Adler  <[email protected]>
 
         Retire legacy dtoa function and DecimalNumber class

Modified: releases/WebKitGTK/webkit-2.24/Source/WTF/wtf/URLHelpers.cpp (242544 => 242545)


--- releases/WebKitGTK/webkit-2.24/Source/WTF/wtf/URLHelpers.cpp	2019-03-06 13:30:42 UTC (rev 242544)
+++ releases/WebKitGTK/webkit-2.24/Source/WTF/wtf/URLHelpers.cpp	2019-03-06 13:30:45 UTC (rev 242545)
@@ -775,27 +775,34 @@
 
 static String toNormalizationFormC(const String& string)
 {
-    auto sourceBuffer = string.charactersWithNullTermination();
+    Vector<UChar> sourceBuffer = string.charactersWithNullTermination();
     ASSERT(sourceBuffer.last() == '\0');
     sourceBuffer.removeLast();
 
-    String result;
-    Vector<UChar, urlBytesBufferLength> 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);
+    if (U_FAILURE(uerror))
+        return { };
+
+    UNormalizationCheckResult checkResult = unorm2_quickCheck(normalizer, sourceBuffer.data(), sourceBuffer.size(), &uerror);
+    if (U_FAILURE(uerror))
+        return { };
+
+    // No need to normalize if already normalized.
+    if (checkResult == UNORM_YES)
+        return string;
+
+    Vector<UChar, urlBytesBufferLength> normalizedCharacters(sourceBuffer.size());
+    auto 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))
+        return { };
 
-    return result;
+    return String(normalizedCharacters.data(), normalizedLength);
 }
 
 String userVisibleURL(const CString& url)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to