Changeset 206758 in webkit
- Timestamp:
- Oct 3, 2016, 3:55:46 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r206753 r206758 1 2016-10-03 Alex Christensen <achristensen@webkit.org> 2 3 URLParser should strip tabs at all locations 4 https://bugs.webkit.org/show_bug.cgi?id=162836 5 6 Reviewed by Geoffrey Garen. 7 8 Covered by adding tabs to each location of each API test 9 except tests that test the encoding of surrogate pairs, 10 because inserting a tab between the pairs changes the encoding. 11 12 * platform/URLParser.cpp: 13 (WebCore::URLParser::takesTwoAdvancesUntilEnd): 14 (WebCore::URLParser::parse): 15 (WebCore::URLParser::parseIPv4Number): 16 (WebCore::URLParser::parseIPv4Host): 17 * platform/URLParser.h: 18 1 19 2016-10-03 Antti Koivisto <antti@apple.com> 2 20 -
trunk/Source/WebCore/platform/URLParser.cpp
r206749 r206758 427 427 428 428 template<typename CharacterType> 429 bool URLParser::takesTwoAdvancesUntilEnd(CodePointIterator<CharacterType> iterator) 430 { 431 if (iterator.atEnd()) 432 return false; 433 advance<CharacterType, ReportSyntaxViolation::No>(iterator); 434 if (iterator.atEnd()) 435 return false; 436 advance<CharacterType, ReportSyntaxViolation::No>(iterator); 437 return iterator.atEnd(); 438 } 439 440 template<typename CharacterType> 429 441 ALWAYS_INLINE bool URLParser::isWindowsDriveLetter(CodePointIterator<CharacterType> iterator) 430 442 { … … 1543 1555 LOG_STATE("FileHost"); 1544 1556 if (isSlashQuestionOrHash(*c)) { 1545 bool windowsQuirk = c.codeUnitsSince(authorityOrHostBegin) == 2 && isWindowsDriveLetter(authorityOrHostBegin); 1557 bool windowsQuirk = takesTwoAdvancesUntilEnd(CodePointIterator<CharacterType>(authorityOrHostBegin, c)) 1558 && isWindowsDriveLetter(authorityOrHostBegin); 1546 1559 if (windowsQuirk) { 1547 1560 syntaxViolation(authorityOrHostBegin); … … 2101 2114 return Nullopt; 2102 2115 while (!iterator.atEnd()) { 2116 if (isTabOrNewline(*iterator)) { 2117 didSeeSyntaxViolation = true; 2118 ++iterator; 2119 continue; 2120 } 2103 2121 if (*iterator == '.') { 2104 2122 ASSERT(!value.hasOverflowed()); … … 2174 2192 bool didSeeSyntaxViolation = false; 2175 2193 while (!iterator.atEnd()) { 2194 if (isTabOrNewline(*iterator)) { 2195 didSeeSyntaxViolation = true; 2196 ++iterator; 2197 continue; 2198 } 2176 2199 if (items.size() >= 4) 2177 2200 return Nullopt; -
trunk/Source/WebCore/platform/URLParser.h
r206735 r206758 72 72 template<typename CharacterType, ReportSyntaxViolation = ReportSyntaxViolation::Yes> 73 73 void advance(CodePointIterator<CharacterType>&, const CodePointIterator<CharacterType>& iteratorForSyntaxViolationPosition); 74 template<typename CharacterType> bool takesTwoAdvancesUntilEnd(CodePointIterator<CharacterType>); 74 75 template<typename CharacterType> void syntaxViolation(const CodePointIterator<CharacterType>&); 75 76 template<typename CharacterType> void fragmentSyntaxViolation(const CodePointIterator<CharacterType>&); -
trunk/Tools/ChangeLog
r206749 r206758 1 2016-10-03 Alex Christensen <achristensen@webkit.org> 2 3 URLParser should ignore tabs at all locations 4 https://bugs.webkit.org/show_bug.cgi?id=162836 5 6 Reviewed by Geoffrey Garen. 7 8 * TestWebKitAPI/Tests/WebCore/URLParser.cpp: 9 (TestWebKitAPI::checkURL): 10 (TestWebKitAPI::checkRelativeURL): 11 (TestWebKitAPI::checkURLDifferences): 12 (TestWebKitAPI::checkRelativeURLDifferences): 13 (TestWebKitAPI::TEST_F): 14 1 15 2016-10-03 Alex Christensen <achristensen@webkit.org> 2 16 -
trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp
r206749 r206758 70 70 } 71 71 72 static void checkURL(const String& urlString, const ExpectedParts& parts, bool checkTabs = true) 72 static String insertTabAtLocation(const String& string, size_t location) 73 { 74 ASSERT(location <= string.length()); 75 return makeString(string.substring(0, location), "\t", string.substring(location)); 76 } 77 78 static ExpectedParts invalidParts(const String& urlStringWithTab) 79 { 80 return {"", "", "", "", 0, "" , "", "", urlStringWithTab}; 81 } 82 83 enum class TestTabs { No, Yes }; 84 85 // Inserting tabs between surrogate pairs changes the encoded value instead of being skipped by the URLParser. 86 const TestTabs testTabsValueForSurrogatePairs = TestTabs::No; 87 88 static void checkURL(const String& urlString, const ExpectedParts& parts, TestTabs testTabs = TestTabs::Yes) 73 89 { 74 90 bool wasEnabled = URLParser::enabled(); … … 103 119 EXPECT_TRUE(URLParser::internalValuesConsistent(oldURL)); 104 120 105 if ( checkTabs) {121 if (testTabs == TestTabs::Yes) { 106 122 for (size_t i = 0; i < urlString.length(); ++i) { 107 String urlStringWithTab = makeString(urlString.substring(0, i), "\t", urlString.substring(i)); 108 ExpectedParts invalidPartsWithTab = {"", "", "", "", 0, "" , "", "", urlStringWithTab}; 109 checkURL(urlStringWithTab, parts.isInvalid() ? invalidPartsWithTab : parts, false); 123 String urlStringWithTab = insertTabAtLocation(urlString, i); 124 checkURL(urlStringWithTab, 125 parts.isInvalid() ? invalidParts(urlStringWithTab) : parts, 126 TestTabs::No); 110 127 } 111 128 } … … 274 291 checkURL("http://./", {"http", "", "", ".", 0, "/", "", "", "http://./"}); 275 292 checkURL("http://.", {"http", "", "", ".", 0, "/", "", "", "http://./"}); 276 checkURL("http://123\t.256/", {"http", "", "", "123.256", 0, "/", "", "", "http://123.256/"});277 checkURL("http://123.\t256/", {"http", "", "", "123.256", 0, "/", "", "", "http://123.256/"});278 293 checkURL("notspecial:/a", {"notspecial", "", "", "", 0, "/a", "", "", "notspecial:/a"}); 279 294 checkURL("notspecial:", {"notspecial", "", "", "", 0, "", "", "", "notspecial:"}); … … 306 321 } 307 322 308 static void checkRelativeURL(const String& urlString, const String& baseURLString, const ExpectedParts& parts, bool checkTabs = true)323 static void checkRelativeURL(const String& urlString, const String& baseURLString, const ExpectedParts& parts, TestTabs testTabs = TestTabs::Yes) 309 324 { 310 325 bool wasEnabled = URLParser::enabled(); … … 339 354 EXPECT_TRUE(URLParser::internalValuesConsistent(oldURL)); 340 355 341 if ( checkTabs) {356 if (testTabs == TestTabs::Yes) { 342 357 for (size_t i = 0; i < urlString.length(); ++i) { 343 String urlStringWithTab = makeString(urlString.substring(0, i), "\t", urlString.substring(i)); 344 ExpectedParts invalidPartsWithTab = {"", "", "", "", 0, "" , "", "", urlStringWithTab}; 345 checkRelativeURL(urlStringWithTab, baseURLString, parts.isInvalid() ? invalidPartsWithTab : parts, false); 358 String urlStringWithTab = insertTabAtLocation(urlString, i); 359 checkRelativeURL(urlStringWithTab, 360 baseURLString, 361 parts.isInvalid() ? invalidParts(urlStringWithTab) : parts, 362 TestTabs::No); 346 363 } 347 364 } … … 423 440 } 424 441 425 static void checkURLDifferences(const String& urlString, const ExpectedParts& partsNew, const ExpectedParts& partsOld )442 static void checkURLDifferences(const String& urlString, const ExpectedParts& partsNew, const ExpectedParts& partsOld, TestTabs testTabs = TestTabs::Yes) 426 443 { 427 444 bool wasEnabled = URLParser::enabled(); … … 456 473 EXPECT_TRUE(URLParser::internalValuesConsistent(oldURL)); 457 474 458 // FIXME: check tabs here like we do for checkURL and checkRelativeURL. 459 } 460 461 static void checkRelativeURLDifferences(const String& urlString, const String& baseURLString, const ExpectedParts& partsNew, const ExpectedParts& partsOld) 475 if (testTabs == TestTabs::Yes) { 476 for (size_t i = 0; i < urlString.length(); ++i) { 477 String urlStringWithTab = insertTabAtLocation(urlString, i); 478 checkURLDifferences(urlStringWithTab, 479 partsNew.isInvalid() ? invalidParts(urlStringWithTab) : partsNew, 480 partsOld.isInvalid() ? invalidParts(urlStringWithTab) : partsOld, 481 TestTabs::No); 482 } 483 } 484 } 485 486 static void checkRelativeURLDifferences(const String& urlString, const String& baseURLString, const ExpectedParts& partsNew, const ExpectedParts& partsOld, TestTabs testTabs = TestTabs::Yes) 462 487 { 463 488 bool wasEnabled = URLParser::enabled(); … … 492 517 EXPECT_TRUE(URLParser::internalValuesConsistent(oldURL)); 493 518 494 // FIXME: check tabs here like we do for checkURL and checkRelativeURL. 519 if (testTabs == TestTabs::Yes) { 520 for (size_t i = 0; i < urlString.length(); ++i) { 521 String urlStringWithTab = insertTabAtLocation(urlString, i); 522 checkRelativeURLDifferences(urlStringWithTab, baseURLString, 523 partsNew.isInvalid() ? invalidParts(urlStringWithTab) : partsNew, 524 partsOld.isInvalid() ? invalidParts(urlStringWithTab) : partsOld, 525 TestTabs::No); 526 } 527 } 495 528 } 496 529 … … 618 651 {"http", "", "", "example.org", 0, "/example.com/", "", "", "http://example.org/example.com/"}, 619 652 {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"}); 620 653 621 654 // This behavior matches Chrome and Firefox, but not WebKit using URL::parse. 622 655 // The behavior of URL::parse is clearly wrong because reparsing file://path would make path the host. … … 648 681 checkRelativeURLDifferences(utf16String(u"http://foo:š©@example.com/bar"), "http://other.com/", 649 682 {"http", "foo", utf16String(u"š©"), "example.com", 0, "/bar", "", "", "http://foo:%F0%9F%92%A9@example.com/bar"}, 650 {"", "", "", "", 0, "", "", "", utf16String(u"http://foo:š©@example.com/bar")} );683 {"", "", "", "", 0, "", "", "", utf16String(u"http://foo:š©@example.com/bar")}, testTabsValueForSurrogatePairs); 651 684 checkRelativeURLDifferences("http://&a:foo(b]c@d:2/", "http://example.org/foo/bar", 652 685 {"http", "&a", "foo(b]c", "d", 2, "/", "", "", "http://&a:foo(b%5Dc@d:2/"}, … … 702 735 checkURLDifferences(utf16String(u"http://host?Ćš#Ćš"), 703 736 {"http", "", "", "host", 0, "/", "%C3%9F%F0%9F%98%8D", utf16String(u"Ćš"), utf16String(u"http://host/?%C3%9F%F0%9F%98%8D#Ćš")}, 704 {"http", "", "", "host", 0, "/", "%C3%9F%F0%9F%98%8D", "%C3%9F%F0%9F%98%8D", "http://host/?%C3%9F%F0%9F%98%8D#%C3%9F%F0%9F%98%8D"} );737 {"http", "", "", "host", 0, "/", "%C3%9F%F0%9F%98%8D", "%C3%9F%F0%9F%98%8D", "http://host/?%C3%9F%F0%9F%98%8D#%C3%9F%F0%9F%98%8D"}, testTabsValueForSurrogatePairs); 705 738 checkURLDifferences(utf16String(u"http://host/path#š©\tš©"), 706 739 {"http", "", "", "host", 0, "/path", "", utf16String(u"š©š©"), utf16String(u"http://host/path#š©š©")}, … … 976 1009 const wchar_t invalidSurrogateEnd = 'A'; 977 1010 checkURL(utf16String<12>({'h', 't', 't', 'p', ':', '/', '/', 'w', '/', surrogateBegin, validSurrogateEnd, '\0'}), 978 {"http", "", "", "w", 0, "/%F0%90%85%95", "", "", "http://w/%F0%90%85%95"}, false);1011 {"http", "", "", "w", 0, "/%F0%90%85%95", "", "", "http://w/%F0%90%85%95"}, testTabsValueForSurrogatePairs); 979 1012 980 1013 // URLParser matches Chrome and Firefox but not URL::parse. … … 996 1029 } 997 1030 998 static void checkURL(const String& urlString, const TextEncoding& encoding, const ExpectedParts& parts, bool checkTabs = true)1031 static void checkURL(const String& urlString, const TextEncoding& encoding, const ExpectedParts& parts, TestTabs testTabs = TestTabs::Yes) 999 1032 { 1000 1033 URLParser parser(urlString, { }, encoding); … … 1010 1043 EXPECT_TRUE(eq(parts.string, url.string())); 1011 1044 1012 if ( checkTabs) {1045 if (testTabs == TestTabs::Yes) { 1013 1046 for (size_t i = 0; i < urlString.length(); ++i) { 1014 String urlStringWithTab = makeString(urlString.substring(0, i), "\t", urlString.substring(i)); 1015 ExpectedParts invalidPartsWithTab = {"", "", "", "", 0, "" , "", "", urlStringWithTab}; 1016 checkURL(urlStringWithTab, encoding, parts.isInvalid() ? invalidPartsWithTab : parts, false); 1047 String urlStringWithTab = insertTabAtLocation(urlString, i); 1048 checkURL(urlStringWithTab, encoding, 1049 parts.isInvalid() ? invalidParts(urlStringWithTab) : parts, 1050 TestTabs::No); 1017 1051 } 1018 1052 } … … 1021 1055 TEST_F(URLParserTest, QueryEncoding) 1022 1056 { 1023 checkURL(utf16String(u"http://host?Ćš#Ćš"), UTF8Encoding(), {"http", "", "", "host", 0, "/", "%C3%9F%F0%9F%98%8D", utf16String(u"Ćš"), utf16String(u"http://host/?%C3%9F%F0%9F%98%8D#Ćš")}, false);1024 checkURL(utf16String(u"http://host?Ćš#Ćš"), UTF8Encoding(), {"http", "", "", "host", 0, "/", "%C3%9F%F0%9F%98%8D", utf16String(u"Ćš"), utf16String(u"http://host/?%C3%9F%F0%9F%98%8D#Ćš")}, false);1057 checkURL(utf16String(u"http://host?Ćš#Ćš"), UTF8Encoding(), {"http", "", "", "host", 0, "/", "%C3%9F%F0%9F%98%8D", utf16String(u"Ćš"), utf16String(u"http://host/?%C3%9F%F0%9F%98%8D#Ćš")}, testTabsValueForSurrogatePairs); 1058 checkURL(utf16String(u"http://host?Ćš#Ćš"), UTF8Encoding(), {"http", "", "", "host", 0, "/", "%C3%9F%F0%9F%98%8D", utf16String(u"Ćš"), utf16String(u"http://host/?%C3%9F%F0%9F%98%8D#Ćš")}, testTabsValueForSurrogatePairs); 1025 1059 1026 1060 TextEncoding latin1(String("latin1"));
Note:
See TracChangeset
for help on using the changeset viewer.