Title: [242353] trunk/Source/WTF
Revision
242353
Author
[email protected]
Date
2019-03-04 07:18:42 -0800 (Mon, 04 Mar 2019)

Log Message

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: trunk/Source/WTF/ChangeLog (242352 => 242353)


--- trunk/Source/WTF/ChangeLog	2019-03-04 14:30:46 UTC (rev 242352)
+++ trunk/Source/WTF/ChangeLog	2019-03-04 15:18:42 UTC (rev 242353)
@@ -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: trunk/Source/WTF/wtf/URLHelpers.cpp (242352 => 242353)


--- trunk/Source/WTF/wtf/URLHelpers.cpp	2019-03-04 14:30:46 UTC (rev 242352)
+++ trunk/Source/WTF/wtf/URLHelpers.cpp	2019-03-04 15:18:42 UTC (rev 242353)
@@ -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