Changeset 242353 in webkit
- Timestamp:
- Mar 4, 2019, 7:18:42 AM (7 years ago)
- Location:
- trunk/Source/WTF
- Files:
-
- 2 edited
-
ChangeLog (modified) (1 diff)
-
wtf/URLHelpers.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r242330 r242353 1 2019-03-04 Michael Catanzaro <mcatanzaro@igalia.com> 2 3 URLHelpers should use unorm2_quickCheck before converting to NFC 4 https://bugs.webkit.org/show_bug.cgi?id=194272 5 6 Reviewed by Darin Adler. 7 8 If the string is already in normalization form C, don't try to normalize it. 9 10 * wtf/URLHelpers.cpp: 11 (WTF::URLHelpers::toNormalizationFormC): 12 1 13 2019-03-02 Darin Adler <darin@apple.com> 2 14 -
trunk/Source/WTF/wtf/URLHelpers.cpp
r241998 r242353 776 776 static String toNormalizationFormC(const String& string) 777 777 { 778 autosourceBuffer = string.charactersWithNullTermination();778 Vector<UChar> sourceBuffer = string.charactersWithNullTermination(); 779 779 ASSERT(sourceBuffer.last() == '\0'); 780 780 sourceBuffer.removeLast(); 781 781 782 String result; 782 UErrorCode uerror = U_ZERO_ERROR; 783 const UNormalizer2* normalizer = unorm2_getNFCInstance(&uerror); 784 if (U_FAILURE(uerror)) 785 return { }; 786 787 UNormalizationCheckResult checkResult = unorm2_quickCheck(normalizer, sourceBuffer.data(), sourceBuffer.size(), &uerror); 788 if (U_FAILURE(uerror)) 789 return { }; 790 791 // No need to normalize if already normalized. 792 if (checkResult == UNORM_YES) 793 return string; 794 783 795 Vector<UChar, urlBytesBufferLength> normalizedCharacters(sourceBuffer.size()); 784 UErrorCode uerror = U_ZERO_ERROR; 785 int32_t normalizedLength = 0; 786 const UNormalizer2* normalizer = unorm2_getNFCInstance(&uerror); 787 if (!U_FAILURE(uerror)) { 788 normalizedLength = unorm2_normalize(normalizer, sourceBuffer.data(), sourceBuffer.size(), normalizedCharacters.data(), normalizedCharacters.size(), &uerror); 789 if (uerror == U_BUFFER_OVERFLOW_ERROR) { 790 uerror = U_ZERO_ERROR; 791 normalizedCharacters.resize(normalizedLength); 792 normalizedLength = unorm2_normalize(normalizer, sourceBuffer.data(), sourceBuffer.size(), normalizedCharacters.data(), normalizedLength, &uerror); 793 } 794 if (!U_FAILURE(uerror)) 795 result = String(normalizedCharacters.data(), normalizedLength); 796 } 797 798 return result; 796 auto normalizedLength = unorm2_normalize(normalizer, sourceBuffer.data(), sourceBuffer.size(), normalizedCharacters.data(), normalizedCharacters.size(), &uerror); 797 if (uerror == U_BUFFER_OVERFLOW_ERROR) { 798 uerror = U_ZERO_ERROR; 799 normalizedCharacters.resize(normalizedLength); 800 normalizedLength = unorm2_normalize(normalizer, sourceBuffer.data(), sourceBuffer.size(), normalizedCharacters.data(), normalizedLength, &uerror); 801 } 802 if (U_FAILURE(uerror)) 803 return { }; 804 805 return String(normalizedCharacters.data(), normalizedLength); 799 806 } 800 807
Note:
See TracChangeset
for help on using the changeset viewer.