Changeset 205521 in webkit
- Timestamp:
- Sep 6, 2016 4:36:36 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r205520 r205521 1 2016-09-06 Alex Christensen <achristensen@webkit.org> 2 3 Punycode encode non-ascii hosts in URLParser 4 https://bugs.webkit.org/show_bug.cgi?id=161655 5 6 Reviewed by Tim Horton. 7 8 Covered by new API tests based on the web platform tests. 9 10 * platform/URLParser.cpp: 11 (WebCore::URLParser::parse): 12 (WebCore::containsOnlyASCII): 13 (WebCore::domainToASCII): 14 1 15 2016-09-06 Saam Barati <sbarati@apple.com> 2 16 -
trunk/Source/WebCore/platform/URLParser.cpp
r205493 r205521 29 29 #include "Logging.h" 30 30 #include <array> 31 #include <unicode/uidna.h> 31 32 #include <wtf/HashMap.h> 32 33 #include <wtf/NeverDestroyed.h> … … 451 452 LOG_STATE("SchemeEndCheckForSlashes"); 452 453 if (*c == '/') { 453 m_buffer.append('/'); 454 m_buffer.append("//"); 455 m_url.m_userStart = m_buffer.length(); 454 456 state = State::PathOrAuthority; 455 457 ++c; … … 1270 1272 } 1271 1273 1274 static bool containsOnlyASCII(const String& string) 1275 { 1276 if (string.is8Bit()) 1277 return charactersAreAllASCII(string.characters8(), string.length()); 1278 return charactersAreAllASCII(string.characters16(), string.length()); 1279 } 1280 1272 1281 static Optional<String> domainToASCII(const String& domain) 1273 1282 { 1274 // FIXME: Implement correctly 1275 CString utf8 = domain.utf8(); 1276 return String(utf8.data(), utf8.length()); 1283 const unsigned hostnameBufferLength = 2048; 1284 1285 if (containsOnlyASCII(domain)) { 1286 if (domain.is8Bit()) 1287 return domain; 1288 Vector<LChar, hostnameBufferLength> buffer; 1289 size_t length = domain.length(); 1290 buffer.reserveInitialCapacity(length); 1291 for (size_t i = 0; i < length; ++i) 1292 buffer.append(domain[i]); 1293 return String(buffer.data(), length); 1294 } 1295 1296 UChar hostnameBuffer[hostnameBufferLength]; 1297 UErrorCode error = U_ZERO_ERROR; 1298 1299 int32_t numCharactersConverted = uidna_IDNToASCII(StringView(domain).upconvertedCharacters(), domain.length(), hostnameBuffer, hostnameBufferLength, UIDNA_ALLOW_UNASSIGNED, nullptr, &error); 1300 1301 if (error == U_ZERO_ERROR) { 1302 LChar buffer[hostnameBufferLength]; 1303 for (int32_t i = 0; i < numCharactersConverted; ++i) { 1304 ASSERT(isASCII(hostnameBuffer[i])); 1305 buffer[i] = hostnameBuffer[i]; 1306 } 1307 return String(buffer, numCharactersConverted); 1308 } 1309 1310 // FIXME: Check for U_BUFFER_OVERFLOW_ERROR and retry with an allocated buffer. 1311 return Nullopt; 1277 1312 } 1278 1313 -
trunk/Tools/ChangeLog
r205493 r205521 1 2016-09-06 Alex Christensen <achristensen@webkit.org> 2 3 Punycode encode non-ascii hosts in URLParser 4 https://bugs.webkit.org/show_bug.cgi?id=161655 5 6 Reviewed by Tim Horton. 7 8 * TestWebKitAPI/Tests/WebCore/URLParser.cpp: 9 (TestWebKitAPI::wideString): 10 (TestWebKitAPI::TEST_F): 11 1 12 2016-09-05 Alex Christensen <achristensen@webkit.org> 2 13 -
trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp
r205493 r205521 83 83 84 84 EXPECT_TRUE(URLParser::allValuesEqual(url, oldURL)); 85 } 86 87 template<size_t length> 88 static String wideString(const wchar_t (&url)[length]) 89 { 90 StringBuilder builder; 91 builder.reserveCapacity(length - 1); 92 for (size_t i = 0; i < length - 1; ++i) 93 builder.append(url[i]); 94 return builder.toString(); 85 95 } 86 96 … … 210 220 checkRelativeURL("http://example\t.\norg", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/", "", "", "http://example.org/"}); 211 221 checkRelativeURL("test", "file:///path1/path2", {"file", "", "", "", 0, "/path1/test", "", "", "file:///path1/test"}); 222 checkRelativeURL(wideString(L"http://www.foo。bar.com"), "http://other.com/", {"http", "", "", "www.foo.bar.com", 0, "/", "", "", "http://www.foo.bar.com/"}); 223 checkRelativeURL(wideString(L"sc://ñ.test/"), "about:blank", {"sc", "", "", "xn--ida.test", 0, "/", "", "", "sc://xn--ida.test/"}); 212 224 } 213 225 … … 352 364 353 365 // URLParser matches Chrome and the spec, but not URL::parse or Firefox. 366 checkURLDifferences(wideString(L"http://0Xc0.0250.01"), 367 {"http", "", "", "192.168.0.1", 0, "/", "", "", "http://192.168.0.1/"}, 368 {"http", "", "", "0xc0.0250.01", 0, "/", "", "", "http://0xc0.0250.01/"}); 354 369 checkURLDifferences("http://host/path%2e.%2E", 355 370 {"http", "", "", "host", 0, "/path...", "", "", "http://host/path..."},
Note: See TracChangeset
for help on using the changeset viewer.