Changeset 31230 in webkit
- Timestamp:
- Mar 22, 2008 2:49:58 AM (16 years ago)
- Location:
- trunk
- Files:
-
- 7 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r31228 r31230 1 2008-03-22 Eric Seidel <eric@webkit.org> 2 3 Reviewed by mjs. 4 5 Fix createElementNS to throw exceptions for invalid qualified names 6 Fixes Acid3 sub-test 23 7 http://bugs.webkit.org/show_bug.cgi?id=16833 8 9 * dom/xhtml/level3/core/documentsetstricterrorchecking02-expected.txt: 10 * fast/dom/Document/createAttributeNS-namespace-err-expected.txt: Added. 11 * fast/dom/Document/createAttributeNS-namespace-err.html: Copied from LayoutTests/fast/dom/Element/dimension-properties-unrendered.html. 12 * fast/dom/Document/createElementNS-namespace-err-expected.txt: Added. 13 * fast/dom/Document/createElementNS-namespace-err.html: Copied from LayoutTests/fast/dom/EntityReference/readonly-exceptions.html. 14 * fast/dom/Document/resources/TEMPLATE.html: Copied from LayoutTests/fast/dom/Element/resources/TEMPLATE.html. 15 * fast/dom/Document/resources/createAttributeNS-namespace-err.js: Added. 16 * fast/dom/Document/resources/createElementNS-namespace-err.js: Added. 17 1 18 2008-03-21 Cameron Zwarich <cwzwarich@uwaterloo.ca> 2 19 -
trunk/LayoutTests/dom/xhtml/level3/core/documentsetstricterrorchecking02-expected.txt
r30052 r31230 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
r31228 r31230 1 2008-03-22 Eric Seidel <eric@webkit.org> 2 3 Reviewed by mjs. 4 5 Fix createElementNS to throw exceptions for invalid qualified names 6 Fixes Acid3 sub-test 23 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-03-21 Cameron Zwarich <cwzwarich@uwaterloo.ca> 2 20 -
trunk/WebCore/dom/Document.cpp
r31160 r31230 108 108 #include "WheelEvent.h" 109 109 #include "XMLHttpRequest.h" 110 #include "XMLNames.h" 110 111 #include "XMLTokenizer.h" 111 112 #include "kjs_binding.h" … … 515 516 PassRefPtr<Element> Document::createElement(const String &name, ExceptionCode& ec) 516 517 { 517 if ( m_isXHTML) {518 if (!isValidName(name)) {519 ec = INVALID_CHARACTER_ERR;520 return 0;521 } 522 523 return HTMLElementFactory::createHTMLElement( AtomicString(name), this, 0, false);524 } else 525 return createElementNS(nullAtom, name, ec);518 if (!isValidName(name)) { 519 ec = INVALID_CHARACTER_ERR; 520 return 0; 521 } 522 523 if (m_isXHTML) 524 return HTMLElementFactory::createHTMLElement(name, this, 0, false); 525 526 return createElement(QualifiedName(nullAtom, name, nullAtom), false, ec); 526 527 } 527 528 … … 717 718 } 718 719 720 static bool hasNamespaceError(const QualifiedName& qName) 721 { 722 static const AtomicString xmlnsNamespaceURI = "http://www.w3.org/2000/xmlns/"; 723 static const AtomicString xmlns = "xmlns"; 724 static const AtomicString xml = "xml"; 725 726 // These checks are from DOM Core Level 2, createElementNS 727 // http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-DocCrElNS 728 if (qName.prefix() == emptyAtom) // createElementNS(null, ":div") 729 return true; 730 if (qName.localName().isEmpty()) // createElementNS(null, ""), createElementNS(null, null), createElementNS() 731 return true; 732 if (!qName.prefix().isEmpty() && qName.namespaceURI().isNull()) // createElementNS(null, "html:div") 733 return true; 734 if (qName.prefix() == xml && qName.namespaceURI() != XMLNames::xmlNamespaceURI) // createElementNS("http://www.example.com", "xml:lang") 735 return true; 736 737 // Required by DOM Level 3 Core and unspecified by DOM Level 2 Core: 738 // http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-DocCrElNS 739 // createElementNS("http://www.w3.org/2000/xmlns/", "foo:bar"), createElementNS(null, "xmlns:bar") 740 if ((qName.prefix() == xmlns && qName.namespaceURI() != xmlnsNamespaceURI) || (qName.prefix() != xmlns && qName.namespaceURI() == xmlnsNamespaceURI)) 741 return true; 742 743 return false; 744 } 745 719 746 // FIXME: This should really be in a possible ElementFactory class 720 747 PassRefPtr<Element> Document::createElement(const QualifiedName& qName, bool createdByParser, ExceptionCode& ec) … … 733 760 e = new Element(qName, document()); 734 761 762 // FIXME: The element factories should be fixed to not ignore qName.prefix() 763 // Instead they should pass the entire qName into element creation so we don't 764 // need to manually set the prefix after creation. 765 // Then this code can become ASSERT(qName == e.qname()); 766 // and Document::createElement can stop taking ExceptionCode& as well. 735 767 if (e && !qName.prefix().isNull()) { 736 768 ec = 0; … … 738 770 if (ec) 739 771 return 0; 740 } 772 } 741 773 742 774 return e.release(); 743 775 } 744 776 745 PassRefPtr<Element> Document::createElementNS(const String &_namespaceURI, const String &qualifiedName, ExceptionCode& ec)777 PassRefPtr<Element> Document::createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode& ec) 746 778 { 747 779 String prefix, localName; … … 751 783 } 752 784 753 RefPtr<Element> e; 754 QualifiedName qName = QualifiedName(AtomicString(prefix), AtomicString(localName), AtomicString(_namespaceURI)); 755 785 QualifiedName qName(prefix, localName, namespaceURI); 786 if (hasNamespaceError(qName)) { 787 ec = NAMESPACE_ERR; 788 return 0; 789 } 790 756 791 return createElement(qName, false, ec); 757 792 } … … 2785 2820 } 2786 2821 2787 bool Document::parseQualifiedName(const String &qualifiedName, String &prefix, String &localName)2822 bool Document::parseQualifiedName(const String& qualifiedName, String& prefix, String& localName) 2788 2823 { 2789 2824 unsigned length = qualifiedName.length(); … … 3490 3525 } 3491 3526 3492 PassRefPtr<Attr> Document::createAttributeNS(const String &namespaceURI, const String &qualifiedName, ExceptionCode& ec) 3493 { 3494 if (qualifiedName.isNull()) { 3527 PassRefPtr<Attr> Document::createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode& ec) 3528 { 3529 String prefix, localName; 3530 if (!parseQualifiedName(qualifiedName, prefix, localName)) { 3531 ec = INVALID_CHARACTER_ERR; 3532 return 0; 3533 } 3534 3535 QualifiedName qName(prefix, localName, namespaceURI); 3536 if (hasNamespaceError(qName)) { 3495 3537 ec = NAMESPACE_ERR; 3496 3538 return 0; 3497 3539 } 3498 3540 3499 String localName = qualifiedName; 3500 String prefix; 3501 int colonpos; 3502 if ((colonpos = qualifiedName.find(':')) >= 0) { 3503 prefix = qualifiedName.substring(0, colonpos); 3504 localName = qualifiedName.substring(colonpos + 1); 3505 } 3506 3507 if (!isValidName(localName)) { 3508 ec = INVALID_CHARACTER_ERR; 3541 // Spec: DOM Level 2 Core: http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-DocCrAttrNS 3542 if (qName.localName() == "xmlns" && qName.namespaceURI() != "http://www.w3.org/2000/xmlns/") { 3543 ec = NAMESPACE_ERR; 3509 3544 return 0; 3510 3545 } 3511 3546 3512 3547 // FIXME: Assume this is a mapped attribute, since createAttribute isn't namespace-aware. There's no harm to XML 3513 3548 // documents if we're wrong. 3514 return new Attr(0, this, new MappedAttribute( QualifiedName(prefix, localName, namespaceURI), StringImpl::empty()));3549 return new Attr(0, this, new MappedAttribute(qName, StringImpl::empty())); 3515 3550 } 3516 3551 -
trunk/WebCore/dom/Document.idl
r30515 r31230 34 34 readonly attribute Element documentElement; 35 35 36 Element createElement(in DOMString tagName)36 Element createElement(in [ConvertNullToNullString] DOMString tagName) 37 37 raises (DOMException); 38 38 DocumentFragment createDocumentFragment(); … … 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.