|
48 | 48 | #include <wtf/StdLibExtras.h> |
49 | 49 | #include <wtf/text/CString.h> |
50 | 50 |
|
51 | | -#include <googleurl/src/url_canon_internal.h> |
52 | 51 | #include <googleurl/src/url_util.h> |
53 | 52 |
|
54 | 53 | using WTF::isASCIILower; |
@@ -943,55 +942,13 @@ String decodeURLEscapeSequences(const String& str, const TextEncoding& encoding) |
943 | 942 |
|
944 | 943 | const char* input = cstr.data(); |
945 | 944 | int inputLength = cstr.length(); |
946 | | - url_canon::RawCanonOutputT<char> unescaped; |
947 | | - for (int i = 0; i < inputLength; i++) { |
948 | | - if (input[i] == '%') { |
949 | | - unsigned char ch; |
950 | | - if (url_canon::DecodeEscaped(input, &i, inputLength, &ch)) |
951 | | - unescaped.push_back(ch); |
952 | | - else { |
953 | | - // Invalid escape sequence, copy the percent literal. |
954 | | - unescaped.push_back('%'); |
955 | | - } |
956 | | - } else { |
957 | | - // Regular non-escaped 8-bit character. |
958 | | - unescaped.push_back(input[i]); |
959 | | - } |
960 | | - } |
961 | 945 |
|
962 | | - // Convert that 8-bit to UTF-16. It's not clear IE does this at all to |
963 | | - // JavaScript URLs, but Firefox and Safari do. |
964 | | - url_canon::RawCanonOutputT<url_parse::UTF16Char> utf16; |
965 | | - for (int i = 0; i < unescaped.length(); i++) { |
966 | | - unsigned char uch = static_cast<unsigned char>(unescaped.at(i)); |
967 | | - if (uch < 0x80) { |
968 | | - // Non-UTF-8, just append directly |
969 | | - utf16.push_back(uch); |
970 | | - } else { |
971 | | - // next_ch will point to the last character of the decoded |
972 | | - // character. |
973 | | - int nextCharacter = i; |
974 | | - unsigned codePoint; |
975 | | - if (url_canon::ReadUTFChar(unescaped.data(), &nextCharacter, |
976 | | - unescaped.length(), &codePoint)) { |
977 | | - // Valid UTF-8 character, convert to UTF-16. |
978 | | - url_canon::AppendUTF16Value(codePoint, &utf16); |
979 | | - i = nextCharacter; |
980 | | - } else { |
981 | | - // KURL.cpp strips any sequences that are not valid UTF-8. This |
982 | | - // sounds scary. Instead, we just keep those invalid code |
983 | | - // points and promote to UTF-16. We copy all characters from |
984 | | - // the current position to the end of the identified sqeuqnce. |
985 | | - while (i < nextCharacter) { |
986 | | - utf16.push_back(static_cast<unsigned char>(unescaped.at(i))); |
987 | | - i++; |
988 | | - } |
989 | | - utf16.push_back(static_cast<unsigned char>(unescaped.at(i))); |
990 | | - } |
991 | | - } |
992 | | - } |
| 946 | + url_canon::RawCanonOutputT<url_parse::UTF16Char> unescaped; |
| 947 | + |
| 948 | + url_util::DecodeURLEscapeSequences(input, inputLength, &unescaped); |
993 | 949 |
|
994 | | - return String(reinterpret_cast<UChar*>(utf16.data()), utf16.length()); |
| 950 | + return String(reinterpret_cast<UChar*>(unescaped.data()), |
| 951 | + unescaped.length()); |
995 | 952 | } |
996 | 953 |
|
997 | 954 | bool KURL::protocolIs(const char* protocol) const |
|
0 commit comments