Changeset 50784 in webkit
- Timestamp:
- Nov 10, 2009 6:07:18 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 24 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r50782 r50784 1 2009-11-10 Yael Aharon <yael.aharon@nokia.com> 2 3 Reviewed by Timothy Hatcher. 4 5 Implement URL decomposition IDL attributes for HTMLAnchorElement. 6 https://bugs.webkit.org/show_bug.cgi?id=29972 7 8 Testcases for setting and getting different parts of the URL. 9 10 * fast/dom/HTMLAnchorElement: Added. 11 * fast/dom/HTMLAnchorElement/script-tests: Added. 12 * fast/dom/HTMLAnchorElement/script-tests/TEMPLATE.html: Added. 13 * fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-hash.js: Added. 14 * fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-host.js: Added. 15 * fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-hostname.js: Added. 16 * fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-pathname.js: Added. 17 * fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-port.js: Added. 18 * fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-protocol.js: Added. 19 * fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-search.js: Added. 20 * fast/dom/HTMLAnchorElement/set-href-attribute-hash-expected.txt: Added. 21 * fast/dom/HTMLAnchorElement/set-href-attribute-hash.html: Added. 22 * fast/dom/HTMLAnchorElement/set-href-attribute-host-expected.txt: Added. 23 * fast/dom/HTMLAnchorElement/set-href-attribute-host.html: Added. 24 * fast/dom/HTMLAnchorElement/set-href-attribute-hostname-expected.txt: Added. 25 * fast/dom/HTMLAnchorElement/set-href-attribute-hostname.html: Added. 26 * fast/dom/HTMLAnchorElement/set-href-attribute-pathname-expected.txt: Added. 27 * fast/dom/HTMLAnchorElement/set-href-attribute-pathname.html: Added. 28 * fast/dom/HTMLAnchorElement/set-href-attribute-port-expected.txt: Added. 29 * fast/dom/HTMLAnchorElement/set-href-attribute-port.html: Added. 30 * fast/dom/HTMLAnchorElement/set-href-attribute-protocol-expected.txt: Added. 31 * fast/dom/HTMLAnchorElement/set-href-attribute-protocol.html: Added. 32 * fast/dom/HTMLAnchorElement/set-href-attribute-search-expected.txt: Added. 33 * fast/dom/HTMLAnchorElement/set-href-attribute-search.html: Added. 34 1 35 2009-11-10 Brian Weinstein <bweinstein@apple.com> 2 36 -
trunk/WebCore/ChangeLog
r50781 r50784 1 2009-11-10 Yael Aharon <yael.aharon@nokia.com> 2 3 Reviewed by Timothy Hatcher. 4 5 Implement URL decomposition IDL attributes for HTMLAnchorElement. 6 https://bugs.webkit.org/show_bug.cgi?id=29972. 7 8 Add methods for setting different parts of the URL in href attribute. 9 10 Tests: fast/dom/HTMLAnchorElement/set-href-attribute-hash.html 11 fast/dom/HTMLAnchorElement/set-href-attribute-host.html 12 fast/dom/HTMLAnchorElement/set-href-attribute-hostname.html 13 fast/dom/HTMLAnchorElement/set-href-attribute-pathname.html 14 fast/dom/HTMLAnchorElement/set-href-attribute-port.html 15 fast/dom/HTMLAnchorElement/set-href-attribute-protocol.html 16 fast/dom/HTMLAnchorElement/set-href-attribute-search.html 17 18 * bindings/js/JSLocationCustom.cpp: 19 (WebCore::JSLocation::setPort): 20 * html/HTMLAnchorElement.cpp: 21 (WebCore::parsePortFromStringPosition): 22 (WebCore::HTMLAnchorElement::setHash): 23 (WebCore::HTMLAnchorElement::setHost): 24 (WebCore::HTMLAnchorElement::setHostname): 25 (WebCore::HTMLAnchorElement::setPathname): 26 (WebCore::HTMLAnchorElement::setPort): 27 (WebCore::HTMLAnchorElement::setProtocol): 28 (WebCore::HTMLAnchorElement::setSearch): 29 * html/HTMLAnchorElement.h: 30 * html/HTMLAnchorElement.idl: 31 * loader/FrameLoader.cpp: 32 (WebCore::FrameLoader::iconURL): 33 * platform/KURL.cpp: 34 (WebCore::KURL::removePort): 35 (WebCore::KURL::setPort): 36 (WebCore::KURL::prettyURL): 37 (WebCore::protocolIsValid): 38 * platform/KURL.h: 39 (WebCore::KURL::canSetHostOrPort): 40 (WebCore::KURL::canSetPathname): 41 (WebCore::KURL::hasPort): 42 * platform/network/soup/ResourceHandleSoup.cpp: 43 (WebCore::): 44 1 45 2009-11-10 Nate Chapin <japhet@chromium.org> 2 46 -
trunk/WebCore/bindings/js/JSLocationCustom.cpp
r48994 r50784 258 258 int port = charactersToInt(portString.data(), portString.size()); 259 259 if (port < 0 || port > 0xFFFF) 260 port = 0; 261 url.setPort(port); 260 url.removePort(); 261 else 262 url.setPort(port); 262 263 263 264 navigateIfAllowed(exec, frame, url, !frame->script()->anyPageIsProcessingUserGesture(), false); -
trunk/WebCore/html/HTMLAnchorElement.cpp
r50315 r50784 59 59 } 60 60 61 // This function does not allow leading spaces before the port number. 62 static unsigned parsePortFromStringPosition(const String& value, unsigned portStart, unsigned& portEnd) 63 { 64 portEnd = portStart; 65 while (isASCIIDigit(value[portEnd])) 66 ++portEnd; 67 return value.substring(portStart, portEnd - portStart).toUInt(); 68 } 69 61 70 bool HTMLAnchorElement::supportsFocus() const 62 71 { … … 363 372 } 364 373 374 void HTMLAnchorElement::setHash(const String& value) 375 { 376 KURL url = href(); 377 if (value[0] == '#') 378 url.setFragmentIdentifier(value.substring(1)); 379 else 380 url.setFragmentIdentifier(value); 381 setHref(url.string()); 382 } 383 365 384 String HTMLAnchorElement::host() const 366 385 { … … 373 392 } 374 393 394 void HTMLAnchorElement::setHost(const String& value) 395 { 396 if (value.isEmpty()) 397 return; 398 KURL url = href(); 399 if (!url.canSetHostOrPort()) 400 return; 401 402 int separator = value.find(':'); 403 if (!separator) 404 return; 405 406 if (separator == -1) 407 url.setHostAndPort(value); 408 else { 409 unsigned portEnd; 410 unsigned port = parsePortFromStringPosition(value, separator + 1, portEnd); 411 if (!port) { 412 // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes 413 // specifically goes against RFC 3986 (p3.2) and 414 // requires setting the port to "0" if it is set to empty string. 415 url.setHostAndPort(value.substring(0, separator + 1) + "0"); 416 } else { 417 if (SecurityOrigin::isDefaultPortForProtocol(port, url.protocol())) 418 url.setHostAndPort(value.substring(0, separator)); 419 else 420 url.setHostAndPort(value.substring(0, portEnd)); 421 } 422 } 423 setHref(url.string()); 424 } 425 375 426 String HTMLAnchorElement::hostname() const 376 427 { … … 378 429 } 379 430 431 void HTMLAnchorElement::setHostname(const String& value) 432 { 433 // Before setting new value: 434 // Remove all leading U+002F SOLIDUS ("/") characters. 435 unsigned i = 0; 436 unsigned hostLength = value.length(); 437 while (value[i] == '/') 438 i++; 439 440 if (i == hostLength) 441 return; 442 443 KURL url = href(); 444 if (!url.canSetHostOrPort()) 445 return; 446 447 url.setHost(value.substring(i)); 448 setHref(url.string()); 449 } 450 380 451 String HTMLAnchorElement::pathname() const 381 452 { … … 383 454 } 384 455 456 void HTMLAnchorElement::setPathname(const String& value) 457 { 458 KURL url = href(); 459 if (!url.canSetPathname()) 460 return; 461 462 if (value[0] == '/') 463 url.setPath(value); 464 else 465 url.setPath("/" + value); 466 467 setHref(url.string()); 468 } 469 385 470 String HTMLAnchorElement::port() const 386 471 { … … 388 473 } 389 474 475 void HTMLAnchorElement::setPort(const String& value) 476 { 477 KURL url = href(); 478 if (!url.canSetHostOrPort()) 479 return; 480 481 // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes 482 // specifically goes against RFC 3986 (p3.2) and 483 // requires setting the port to "0" if it is set to empty string. 484 unsigned port = value.toUInt(); 485 if (SecurityOrigin::isDefaultPortForProtocol(port, url.protocol())) 486 url.removePort(); 487 else 488 url.setPort(port); 489 490 setHref(url.string()); 491 } 492 390 493 String HTMLAnchorElement::protocol() const 391 494 { 392 495 return href().protocol() + ":"; 496 } 497 498 void HTMLAnchorElement::setProtocol(const String& value) 499 { 500 int separator = value.find(':'); 501 502 if (!separator) 503 return; 504 if (value.isEmpty()) 505 return; 506 507 KURL url = href(); 508 // Following Firefox 3.5.2 which removes anything after the first ":" 509 String newProtocol = value.substring(0, separator); 510 if (!protocolIsValid(newProtocol)) 511 return; 512 url.setProtocol(newProtocol); 513 514 setHref(url.string()); 393 515 } 394 516 … … 397 519 String query = href().query(); 398 520 return query.isEmpty() ? "" : "?" + query; 521 } 522 523 void HTMLAnchorElement::setSearch(const String& value) 524 { 525 KURL url = href(); 526 String newSearch = (value[0] == '?') ? value.substring(1) : value; 527 // Make sure that '#' in the query does not leak to the hash. 528 url.setQuery(newSearch.replace('#', "%23")); 529 530 setHref(url.string()); 399 531 } 400 532 -
trunk/WebCore/html/HTMLAnchorElement.h
r49809 r50784 63 63 64 64 String hash() const; 65 void setHash(const String&); 66 65 67 String host() const; 68 void setHost(const String&); 69 66 70 String hostname() const; 71 void setHostname(const String&); 72 67 73 String pathname() const; 74 void setPathname(const String&); 75 68 76 String port() const; 77 void setPort(const String&); 78 69 79 String protocol() const; 80 void setProtocol(const String&); 81 70 82 String search() const; 83 void setSearch(const String&); 84 71 85 String text() const; 72 86 -
trunk/WebCore/html/HTMLAnchorElement.idl
r45893 r50784 38 38 attribute [ConvertNullToNullString, Reflect] DOMString type; 39 39 40 // IE Extensions 40 #if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C 41 41 readonly attribute DOMString hash; 42 42 readonly attribute DOMString host; … … 46 46 readonly attribute DOMString protocol; 47 47 readonly attribute DOMString search; 48 #else 49 attribute [ConvertNullToNullString] DOMString hash; 50 attribute [ConvertNullToNullString] DOMString host; 51 attribute [ConvertNullToNullString] DOMString hostname; 52 attribute [ConvertNullToNullString] DOMString pathname; 53 attribute [ConvertNullToNullString] DOMString port; 54 attribute [ConvertNullToNullString] DOMString protocol; 55 attribute [ConvertNullToNullString] DOMString search; 56 #endif 57 48 58 readonly attribute DOMString text; 49 59 -
trunk/WebCore/loader/FrameLoader.cpp
r50698 r50784 606 606 url.setProtocol(m_URL.protocol()); 607 607 url.setHost(m_URL.host()); 608 if ( int port = m_URL.port())609 url.setPort( port);608 if (m_URL.hasPort()) 609 url.setPort(m_URL.port()); 610 610 url.setPath("/favicon.ico"); 611 611 return url; -
trunk/WebCore/platform/KURL.cpp
r50395 r50784 686 686 } 687 687 688 void KURL::removePort() 689 { 690 if (m_hostEnd == m_portEnd) 691 return; 692 parse(m_string.left(m_hostEnd) + m_string.substring(m_portEnd)); 693 } 694 688 695 void KURL::setPort(unsigned short i) 689 696 { … … 691 698 return; 692 699 693 if (i) { 694 bool colonNeeded = m_portEnd == m_hostEnd; 695 int portStart = (colonNeeded ? m_hostEnd : m_hostEnd + 1); 696 697 parse(m_string.left(portStart) + (colonNeeded ? ":" : "") + String::number(i) + m_string.substring(m_portEnd)); 698 } else 699 parse(m_string.left(m_hostEnd) + m_string.substring(m_portEnd)); 700 bool colonNeeded = m_portEnd == m_hostEnd; 701 int portStart = (colonNeeded ? m_hostEnd : m_hostEnd + 1); 702 703 parse(m_string.left(portStart) + (colonNeeded ? ":" : "") + String::number(i) + m_string.substring(m_portEnd)); 700 704 } 701 705 … … 820 824 } 821 825 append(authority, host()); 822 if ( port() != 0) {826 if (hasPort()) { 823 827 authority.append(':'); 824 828 append(authority, String::number(port())); … … 1625 1629 } 1626 1630 1631 bool protocolIsValid(const String& protocol) 1632 { 1633 if (!isSchemeFirstChar(protocol[0])) 1634 return false; 1635 unsigned protocolLength = protocol.length(); 1636 for (unsigned i = 1; i < protocolLength; i++) { 1637 if (!isSchemeChar(protocol[i])) 1638 return false; 1639 } 1640 return true; 1641 } 1642 1627 1643 String mimeTypeFromDataURL(const String& url) 1628 1644 { -
trunk/WebCore/platform/KURL.h
r47907 r50784 79 79 KURL(const KURL& base, const String& relative, const TextEncoding&); 80 80 81 81 82 #if USE(GOOGLEURL) 82 83 // For conversions for other structures that have already parsed and … … 105 106 bool hasPath() const; 106 107 108 // Returns true if you can set the host and port for the URL. 109 // Non-hierarchical URLs don't have a host and port. 110 bool canSetHostOrPort() const { return isHierarchical(); } 111 112 bool canSetPathname() const { return isHierarchical(); } 113 107 114 #if USE(GOOGLEURL) 108 115 const String& string() const { return m_url.string(); } … … 114 121 String host() const; 115 122 unsigned short port() const; 123 bool hasPort() const; 116 124 String user() const; 117 125 String pass() const; … … 136 144 void setHost(const String&); 137 145 138 // Setting the port to 0 will clear any port from the URL.146 void removePort(); 139 147 void setPort(unsigned short); 140 148 … … 255 263 bool protocolIs(const String& url, const char* protocol); 256 264 bool protocolIsJavaScript(const String& url); 265 bool protocolIsValid(const String& protocol); 257 266 258 267 String mimeTypeFromDataURL(const String& url); … … 318 327 } 319 328 329 inline bool KURL::hasPort() const 330 { 331 return m_hostEnd < m_portEnd; 332 } 333 320 334 inline bool KURL::protocolInHTTPFamily() const 321 335 { -
trunk/WebCore/platform/network/soup/ResourceHandleSoup.cpp
r50423 r50784 874 874 url.removeFragmentIdentifier(); 875 875 url.setQuery(String()); 876 url. setPort(0);876 url.removePort(); 877 877 878 878 #if !PLATFORM(WIN_OS)
Note: See TracChangeset
for help on using the changeset viewer.