Changeset 29952 in webkit
- Timestamp:
- Feb 3, 2008 3:46:58 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 7 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r29947 r29952 1 2008-02-03 Eric Seidel <eric@webkit.org> 2 3 Reviewed by darin. 4 5 Make createElementNS and createAttributeNS follow the (vague) DOM Core 2 spec 6 by throwing exceptions for more types of invalid qualified names. 7 http://bugs.webkit.org/show_bug.cgi?id=16833 8 9 These tests were originally from Hixie's Acid3, then I added some, then Josh 10 from mozilla added more. We pass all of mine and Hixie's. Some of Josh's 11 still fail (extreme edge cases, such as *which* exception to throw when 12 a QName is a valid XML name but invalid QName, etc.) 13 The "failure" results are still being checked in, perhaps some day we'll "fix" them. 14 15 * dom/xhtml/level3/core/documentsetstricterrorchecking02-expected.txt: 16 * fast/dom/Document/createAttributeNS-namespace-err-expected.txt: Added. 17 * fast/dom/Document/createAttributeNS-namespace-err.html: Added. 18 * fast/dom/Document/createElementNS-namespace-err-expected.txt: Added. 19 * fast/dom/Document/createElementNS-namespace-err.html: Added. 20 * fast/dom/Document/resources/TEMPLATE.html: Added. 21 * fast/dom/Document/resources/createAttributeNS-namespace-err.js: Added. 22 * fast/dom/Document/resources/createElementNS-namespace-err.js: Added. 23 1 24 2008-02-03 Darin Adler <darin@apple.com> 2 25 -
trunk/LayoutTests/dom/xhtml/level3/core/documentsetstricterrorchecking02-expected.txt
r11962 r29952 1 1 Test http://www.w3.org/2001/DOM-Test-Suite/level3/core/documentsetstricterrorchecking02 2 Status failure 3 Message NAMESPACE_ERR_documentsetstricterrorchecking02: assertTrue failed 2 Status Success -
trunk/WebCore/ChangeLog
r29951 r29952 1 2008-02-03 Eric Seidel <eric@webkit.org> 2 3 Reviewed by darin. 4 5 Make createElementNS and createAttributeNS follow the (vague) DOM Core 2 spec 6 by throwing exceptions for more types of invalid qualified names. 7 http://bugs.webkit.org/show_bug.cgi?id=16833 8 9 Tests: fast/dom/Document/createAttributeNS-namespace-err.html 10 fast/dom/Document/createElementNS-namespace-err.html 11 12 * dom/Document.cpp: 13 (WebCore::Document::createElement): 14 (WebCore::hasNamespaceError): 15 (WebCore::Document::createElementNS): 16 (WebCore::Document::createAttributeNS): 17 * dom/Document.idl: 18 1 19 2008-02-03 Nikolas Zimmermann <zimmermann@kde.org> 2 20 -
trunk/WebCore/dom/Document.cpp
r29905 r29952 103 103 #include "WheelEvent.h" 104 104 #include "XMLHttpRequest.h" 105 #include "XMLNames.h" 105 106 #include "XMLTokenizer.h" 106 107 #include "kjs_binding.h" … … 509 510 } 510 511 511 return HTMLElementFactory::createHTMLElement( AtomicString(name), this, 0, false);512 return HTMLElementFactory::createHTMLElement(name, this, 0, false); 512 513 } else 513 514 return createElementNS(nullAtom, name, ec); … … 700 701 } 701 702 703 static bool hasNamespaceError(const QualifiedName& qName) 704 { 705 static const AtomicString xmlnsNamespaceURI = "http://www.w3.org/2000/xmlns/"; 706 static const AtomicString xmlns = "xmlns"; 707 static const AtomicString xml = "xml"; 708 709 // These checks are from DOM Core Level 2, createElementNS 710 // http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-DocCrElNS 711 if (qName.prefix() == emptyAtom) // createElementNS(null, ":div") 712 return true; 713 if (qName.localName().isEmpty()) // createElementNS(null, ""), createElementNS(null, null), createElementNS() 714 return true; 715 if (!qName.prefix().isEmpty() && qName.namespaceURI().isNull()) // createElementNS(null, "html:div") 716 return true; 717 if (qName.prefix() == xml && qName.namespaceURI() != XMLNames::xmlNamespaceURI) // createElementNS("http://www.example.com", "xml:lang") 718 return true; 719 720 // Required by DOM Level 3 Core and unspecified by DOM Level 2 Core: 721 // http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-DocCrElNS 722 // createElementNS("http://www.w3.org/2000/xmlns/", "foo:bar"), createElementNS(null, "xmlns:bar") 723 if ((qName.prefix() == xmlns && qName.namespaceURI() != xmlnsNamespaceURI) || (qName.prefix() != xmlns && qName.namespaceURI() == xmlnsNamespaceURI)) 724 return true; 725 726 return false; 727 } 728 702 729 // FIXME: This should really be in a possible ElementFactory class 703 730 PassRefPtr<Element> Document::createElement(const QualifiedName& qName, bool createdByParser, ExceptionCode& ec) … … 716 743 e = new Element(qName, document()); 717 744 745 // FIXME: The element factories should be fixed to not ignore qName.prefix() 746 // Instead they should pass the entire qName into element creation so we don't 747 // need to manually set the prefix after creation. 748 // Then this code can become ASSERT(qName == e.qname()); 749 // and Document::createElement can stop taking ExceptionCode& as well. 718 750 if (e && !qName.prefix().isNull()) { 719 751 ec = 0; … … 721 753 if (ec) 722 754 return 0; 723 } 755 } 724 756 725 757 return e.release(); 726 758 } 727 759 728 PassRefPtr<Element> Document::createElementNS(const String &_namespaceURI, const String &qualifiedName, ExceptionCode& ec)760 PassRefPtr<Element> Document::createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode& ec) 729 761 { 730 762 String prefix, localName; … … 734 766 } 735 767 736 RefPtr<Element> e; 737 QualifiedName qName = QualifiedName(AtomicString(prefix), AtomicString(localName), AtomicString(_namespaceURI)); 738 768 QualifiedName qName(prefix, localName, namespaceURI); 769 if (hasNamespaceError(qName)) { 770 ec = NAMESPACE_ERR; 771 return 0; 772 } 773 739 774 return createElement(qName, false, ec); 740 775 } 741 776 742 Element *Document::getElementById(const AtomicString& elementId) const777 Element* Document::getElementById(const AtomicString& elementId) const 743 778 { 744 779 if (elementId.length() == 0) … … 2678 2713 } 2679 2714 2680 bool Document::parseQualifiedName(const String &qualifiedName, String &prefix, String &localName)2715 bool Document::parseQualifiedName(const String& qualifiedName, String& prefix, String& localName) 2681 2716 { 2682 2717 unsigned length = qualifiedName.length(); … … 3391 3426 } 3392 3427 3393 PassRefPtr<Attr> Document::createAttributeNS(const String &namespaceURI, const String &qualifiedName, ExceptionCode& ec) 3394 { 3395 if (qualifiedName.isNull()) { 3428 PassRefPtr<Attr> Document::createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode& ec) 3429 { 3430 String prefix, localName; 3431 if (!parseQualifiedName(qualifiedName, prefix, localName)) { 3432 ec = INVALID_CHARACTER_ERR; 3433 return 0; 3434 } 3435 3436 QualifiedName qName(prefix, localName, namespaceURI); 3437 if (hasNamespaceError(qName)) { 3396 3438 ec = NAMESPACE_ERR; 3397 3439 return 0; 3398 3440 } 3399 3441 3400 String localName = qualifiedName; 3401 String prefix; 3402 int colonpos; 3403 if ((colonpos = qualifiedName.find(':')) >= 0) { 3404 prefix = qualifiedName.substring(0, colonpos); 3405 localName = qualifiedName.substring(colonpos + 1); 3406 } 3407 3408 if (!isValidName(localName)) { 3409 ec = INVALID_CHARACTER_ERR; 3442 // Spec: DOM Level 2 Core: http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-DocCrAttrNS 3443 if (qName.localName() == "xmlns" && qName.namespaceURI() != "http://www.w3.org/2000/xmlns/") { 3444 ec = NAMESPACE_ERR; 3410 3445 return 0; 3411 3446 } 3412 3447 3413 3448 // FIXME: Assume this is a mapped attribute, since createAttribute isn't namespace-aware. There's no harm to XML 3414 3449 // documents if we're wrong. 3415 return new Attr(0, this, new MappedAttribute( QualifiedName(prefix, localName, namespaceURI), StringImpl::empty()));3450 return new Attr(0, this, new MappedAttribute(qName, StringImpl::empty())); 3416 3451 } 3417 3452 -
trunk/WebCore/dom/Document.idl
r29672 r29952 56 56 raises (DOMException); 57 57 [OldStyleObjC] Element createElementNS(in [ConvertNullToNullString] DOMString namespaceURI, 58 in DOMString qualifiedName)58 in [ConvertNullToNullString] DOMString qualifiedName) 59 59 raises (DOMException); 60 60 [OldStyleObjC] Attr createAttributeNS(in [ConvertNullToNullString] DOMString namespaceURI, 61 in DOMString qualifiedName)61 in [ConvertNullToNullString] DOMString qualifiedName) 62 62 raises (DOMException); 63 63 [OldStyleObjC] NodeList getElementsByTagNameNS(in [ConvertNullToNullString] DOMString namespaceURI,
Note: See TracChangeset
for help on using the changeset viewer.