Changeset 206162 in webkit
- Timestamp:
- Sep 20, 2016 11:46:26 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r206161 r206162 1 2016-09-20 Alex Christensen <achristensen@webkit.org> 2 3 Align URLParser with web platform tests when parsing non-special relative URLs ending in AuthorityOrHost state 4 https://bugs.webkit.org/show_bug.cgi?id=162251 5 6 Reviewed by Tim Horton. 7 8 Covered by new and updated API tests. 9 10 * platform/URLParser.cpp: 11 (WebCore::URLParser::parse): 12 Fix parsing of non-special URLs that end after scheme:// with no authority. 13 We used to assume that parsing non-special schemes would never end with just scheme:// but a string can indeed end right there. 14 When a non-special relative URL contains just scheme:// we need the resulting URL to be valid to conform with the web platform tests. 15 (WebCore::URLParser::parseHostAndPort): 16 Renamed to reflect what the function actually does. 17 (WebCore::URLParser::internalValuesConsistent): 18 Add utility function for testing. 19 (WebCore::URLParser::parseHost): Deleted. 20 * platform/URLParser.h: 21 1 22 2016-09-20 Javier Fernandez <jfernandez@igalia.com> 2 23 -
trunk/Source/WebCore/platform/URLParser.cpp
r206159 r206162 1000 1000 state = State::SpecialAuthoritySlashes; 1001 1001 } else { 1002 m_url.m_userStart = m_asciiBuffer.size();1003 m_url.m_userEnd = m_url.m_userStart;1004 m_url.m_passwordEnd = m_url.m_userStart;1005 m_url.m_hostEnd = m_url.m_userStart;1006 m_url.m_portEnd = m_url.m_userStart;1007 1002 auto maybeSlash = c; 1008 1003 incrementIteratorSkippingTabAndNewLine<serialized>(maybeSlash); 1009 1004 if (!maybeSlash.atEnd() && *maybeSlash == '/') { 1010 1005 m_asciiBuffer.append('/'); 1011 m_url.m_ pathAfterLastSlash = m_url.m_userStart + 1;1006 m_url.m_userStart = m_asciiBuffer.size(); 1012 1007 state = State::PathOrAuthority; 1013 1008 c = maybeSlash; 1014 1009 ASSERT(*c == '/'); 1015 1010 } else { 1011 m_url.m_userStart = m_asciiBuffer.size(); 1012 m_url.m_userEnd = m_url.m_userStart; 1013 m_url.m_passwordEnd = m_url.m_userStart; 1014 m_url.m_hostEnd = m_url.m_userStart; 1015 m_url.m_portEnd = m_url.m_userStart; 1016 1016 m_url.m_pathAfterLastSlash = m_url.m_userStart; 1017 1017 m_url.m_cannotBeABaseURL = true; … … 1077 1077 ++c; 1078 1078 authorityOrHostBegin = c; 1079 } else 1079 } else { 1080 ASSERT(m_asciiBuffer.last() == '/'); 1081 m_url.m_userStart = m_asciiBuffer.size() - 1; 1082 m_url.m_userEnd = m_url.m_userStart; 1083 m_url.m_passwordEnd = m_url.m_userStart; 1084 m_url.m_hostEnd = m_url.m_userStart; 1085 m_url.m_portEnd = m_url.m_userStart; 1086 m_url.m_pathAfterLastSlash = m_url.m_userStart + 1; 1080 1087 state = State::Path; 1088 } 1081 1089 break; 1082 1090 case State::Relative: … … 1163 1171 m_url.m_userEnd = m_asciiBuffer.size(); 1164 1172 m_url.m_passwordEnd = m_url.m_userEnd; 1165 if (!parseHost <serialized>(CodePointIterator<CharacterType>(authorityOrHostBegin, c)))1173 if (!parseHostAndPort<serialized>(CodePointIterator<CharacterType>(authorityOrHostBegin, c))) 1166 1174 return failure(input, length); 1167 1175 if (!isSlash) { … … 1180 1188 LOG_STATE("Host"); 1181 1189 if (*c == '/' || *c == '?' || *c == '#') { 1182 if (!parseHost <serialized>(CodePointIterator<CharacterType>(authorityOrHostBegin, c)))1190 if (!parseHostAndPort<serialized>(CodePointIterator<CharacterType>(authorityOrHostBegin, c))) 1183 1191 return failure(input, length); 1184 1192 state = State::Path; … … 1310 1318 break; 1311 1319 } 1312 if (!parseHost <serialized>(CodePointIterator<CharacterType>(authorityOrHostBegin, c)))1320 if (!parseHostAndPort<serialized>(CodePointIterator<CharacterType>(authorityOrHostBegin, c))) 1313 1321 return failure(input, length); 1314 1322 … … 1434 1442 case State::PathOrAuthority: 1435 1443 LOG_FINAL_STATE("PathOrAuthority"); 1444 m_url.m_userEnd = m_asciiBuffer.size(); 1445 m_url.m_passwordEnd = m_url.m_userEnd; 1446 m_url.m_hostEnd = m_url.m_userEnd; 1447 m_url.m_portEnd = m_url.m_userEnd; 1448 m_url.m_pathAfterLastSlash = m_url.m_userEnd; 1436 1449 m_url.m_pathEnd = m_url.m_pathAfterLastSlash; 1437 1450 m_url.m_queryEnd = m_url.m_pathAfterLastSlash; … … 1471 1484 m_url.m_userEnd = m_asciiBuffer.size(); 1472 1485 m_url.m_passwordEnd = m_url.m_userEnd; 1473 FALLTHROUGH; 1486 if (authorityOrHostBegin.atEnd()) { 1487 m_url.m_hostEnd = m_url.m_userEnd; 1488 m_url.m_portEnd = m_url.m_userEnd; 1489 } else if (!parseHostAndPort<serialized>(authorityOrHostBegin)) 1490 return failure(input, length); 1491 m_asciiBuffer.append('/'); 1492 m_url.m_pathEnd = m_url.m_portEnd + 1; 1493 m_url.m_pathAfterLastSlash = m_url.m_pathEnd; 1494 m_url.m_queryEnd = m_url.m_pathEnd; 1495 m_url.m_fragmentEnd = m_url.m_pathEnd; 1496 break; 1474 1497 case State::Host: 1475 if (state == State::Host) 1476 LOG_FINAL_STATE("Host"); 1477 if (!parseHost<serialized>(authorityOrHostBegin)) 1498 LOG_FINAL_STATE("Host"); 1499 if (!parseHostAndPort<serialized>(authorityOrHostBegin)) 1478 1500 return failure(input, length); 1479 1501 m_asciiBuffer.append('/'); … … 1529 1551 } 1530 1552 1531 if (!parseHost <serialized>(CodePointIterator<CharacterType>(authorityOrHostBegin, c)))1553 if (!parseHostAndPort<serialized>(CodePointIterator<CharacterType>(authorityOrHostBegin, c))) 1532 1554 return failure(input, length); 1533 1555 … … 1584 1606 m_url.m_isValid = true; 1585 1607 LOG(URLParser, "Parsed URL <%s>", m_url.m_string.utf8().data()); 1608 ASSERT(internalValuesConsistent(m_url)); 1586 1609 return m_url; 1587 1610 } … … 2007 2030 2008 2031 template<bool serialized, typename CharacterType> 2009 bool URLParser::parseHost (CodePointIterator<CharacterType> iterator)2032 bool URLParser::parseHostAndPort(CodePointIterator<CharacterType> iterator) 2010 2033 { 2011 2034 if (iterator.atEnd()) … … 2225 2248 } 2226 2249 2250 bool URLParser::internalValuesConsistent(const URL& url) 2251 { 2252 return url.m_schemeEnd <= url.m_userStart 2253 && url.m_userStart <= url.m_userEnd 2254 && url.m_userEnd <= url.m_passwordEnd 2255 && url.m_passwordEnd <= url.m_hostEnd 2256 && url.m_hostEnd <= url.m_hostEnd 2257 && url.m_portEnd <= url.m_pathAfterLastSlash 2258 && url.m_pathAfterLastSlash <= url.m_pathEnd 2259 && url.m_pathEnd <= url.m_queryEnd 2260 && url.m_queryEnd <= url.m_fragmentEnd 2261 && (url.m_isValid ? url.m_fragmentEnd == url.m_string.length() : !url.m_fragmentEnd); 2262 // FIXME: Why do we even store m_fragmentEnd? 2263 // It should be able to be deduced from m_isValid and m_string.length() to save memory. 2264 } 2265 2227 2266 static bool urlParserEnabled = false; 2228 2267 -
trunk/Source/WebCore/platform/URLParser.h
r206125 r206162 39 39 WEBCORE_EXPORT URL parse(const String&, const URL& = { }, const TextEncoding& = UTF8Encoding()); 40 40 WEBCORE_EXPORT URL parseSerializedURL(const String&); 41 41 42 WEBCORE_EXPORT static bool allValuesEqual(const URL&, const URL&); 43 WEBCORE_EXPORT static bool internalValuesConsistent(const URL&); 42 44 43 45 WEBCORE_EXPORT static bool enabled(); … … 57 59 template<bool serialized, typename CharacterType> URL parse(const CharacterType*, const unsigned length, const URL&, const TextEncoding&); 58 60 template<bool serialized, typename CharacterType> void parseAuthority(CodePointIterator<CharacterType>); 59 template<bool serialized, typename CharacterType> bool parseHost (CodePointIterator<CharacterType>);61 template<bool serialized, typename CharacterType> bool parseHostAndPort(CodePointIterator<CharacterType>); 60 62 template<bool serialized, typename CharacterType> bool parsePort(CodePointIterator<CharacterType>&); 61 63 template<typename CharacterType> URL failure(const CharacterType*, unsigned length); -
trunk/Tools/ChangeLog
r206159 r206162 1 2016-09-20 Alex Christensen <achristensen@webkit.org> 2 3 Align URLParser with web platform tests when parsing non-special relative URLs ending in AuthorityOrHost state 4 https://bugs.webkit.org/show_bug.cgi?id=162251 5 6 Reviewed by Tim Horton. 7 8 * TestWebKitAPI/Tests/WebCore/URLParser.cpp: 9 (TestWebKitAPI::checkURL): 10 (TestWebKitAPI::TEST_F): 11 (TestWebKitAPI::checkRelativeURL): 12 (TestWebKitAPI::checkURLDifferences): 13 (TestWebKitAPI::checkRelativeURLDifferences): 14 1 15 2016-09-20 Alex Christensen <achristensen@webkit.org> 2 16 -
trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp
r206159 r206162 83 83 84 84 EXPECT_TRUE(URLParser::allValuesEqual(url, oldURL)); 85 EXPECT_TRUE(URLParser::internalValuesConsistent(url)); 86 EXPECT_TRUE(URLParser::internalValuesConsistent(oldURL)); 85 87 } 86 88 … … 202 204 checkURL("sc:/pa", {"sc", "", "", "", 0, "/pa", "", "", "sc:/pa"}); 203 205 checkURL("sc:/pa/", {"sc", "", "", "", 0, "/pa/", "", "", "sc:/pa/"}); 206 checkURL("notspecial:/notuser:notpassword@nothost", {"notspecial", "", "", "", 0, "/notuser:notpassword@nothost", "", "", "notspecial:/notuser:notpassword@nothost"}); 204 207 checkURL("sc://pa/", {"sc", "", "", "pa", 0, "/", "", "", "sc://pa/"}); 205 208 checkURL("http://host \a ", {"http", "", "", "host", 0, "/", "", "", "http://host/"}); 206 checkURL("notspecial:/", {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"});207 209 checkURL("notspecial:/a", {"notspecial", "", "", "", 0, "/a", "", "", "notspecial:/a"}); 208 210 checkURL("notspecial:", {"notspecial", "", "", "", 0, "", "", "", "notspecial:"}); … … 211 213 checkURL("http://256./", {"http", "", "", "256.", 0, "/", "", "", "http://256./"}); 212 214 checkURL("http://123.256/", {"http", "", "", "123.256", 0, "/", "", "", "http://123.256/"}); 215 checkURL("notspecial:/a", {"notspecial", "", "", "", 0, "/a", "", "", "notspecial:/a"}); 216 checkURL("notspecial:", {"notspecial", "", "", "", 0, "", "", "", "notspecial:"}); 213 217 // FIXME: Fix and add a test with an invalid surrogate pair at the end with a space as the second code unit. 214 218 … … 247 251 248 252 EXPECT_TRUE(URLParser::allValuesEqual(url, oldURL)); 253 EXPECT_TRUE(URLParser::internalValuesConsistent(url)); 254 EXPECT_TRUE(URLParser::internalValuesConsistent(oldURL)); 249 255 } 250 256 … … 288 294 checkRelativeURL(" \a baz", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/baz", "", "", "http://example.org/foo/baz"}); 289 295 checkRelativeURL("~", "http://example.org", {"http", "", "", "example.org", 0, "/~", "", "", "http://example.org/~"}); 290 checkRelativeURL("notspecial:/", "about:blank", {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"});291 296 checkRelativeURL("notspecial:", "about:blank", {"notspecial", "", "", "", 0, "", "", "", "notspecial:"}); 292 checkRelativeURL("notspecial:/", "http://host", {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"});293 297 checkRelativeURL("notspecial:", "http://host", {"notspecial", "", "", "", 0, "", "", "", "notspecial:"}); 294 298 checkRelativeURL("http:", "http://host", {"http", "", "", "host", 0, "/", "", "", "http://host/"}); … … 325 329 326 330 EXPECT_FALSE(URLParser::allValuesEqual(url, oldURL)); 331 EXPECT_TRUE(URLParser::internalValuesConsistent(url)); 332 EXPECT_TRUE(URLParser::internalValuesConsistent(oldURL)); 327 333 } 328 334 … … 356 362 357 363 EXPECT_FALSE(URLParser::allValuesEqual(url, oldURL)); 364 EXPECT_TRUE(URLParser::internalValuesConsistent(url)); 365 EXPECT_TRUE(URLParser::internalValuesConsistent(oldURL)); 358 366 } 359 367 … … 548 556 {"https", "@test@test", "", "example", 800, "/", "", "", "https://%40test%40test@example:800/"}, 549 557 {"", "", "", "", 0, "", "", "", "https://@test@test@example:800/"}); 558 checkRelativeURLDifferences("foo://", "http://example.org/foo/bar", 559 {"foo", "", "", "", 0, "/", "", "", "foo:///"}, 560 {"foo", "", "", "", 0, "//", "", "", "foo://"}); 561 562 // This matches the spec and web platform tests, but not Chrome, Firefox, or URL::parse. 563 checkRelativeURLDifferences("notspecial:/", "about:blank", 564 {"notspecial", "", "", "", 0, "", "", "", "notspecial:/"}, 565 {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"}); 566 checkRelativeURLDifferences("notspecial:/", "http://host", 567 {"notspecial", "", "", "", 0, "", "", "", "notspecial:/"}, 568 {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"}); 569 checkURLDifferences("notspecial:/", 570 {"notspecial", "", "", "", 0, "", "", "", "notspecial:/"}, 571 {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"}); 550 572 } 551 573
Note: See TracChangeset
for help on using the changeset viewer.