diff --git a/lib/DOM/Document.php b/lib/DOM/Document.php index 4d60f6e..5f00bb1 100644 --- a/lib/DOM/Document.php +++ b/lib/DOM/Document.php @@ -36,6 +36,9 @@ class Document extends \DOMDocument { } public function createAttribute($name) { + // Normalize the attribute name per modern DOM specifications. + $name = strtolower(trim($name)); + try { return parent::createAttribute($name); } catch (\DOMException $e) { @@ -49,6 +52,12 @@ class Document extends \DOMDocument { } public function createAttributeNS($namespaceURI, $qualifiedName) { + // Normalize the attribute name and namespace URI per modern DOM specifications. + if ($namespaceURI !== null) { + $namespaceURI = strtolower(trim($namespaceURI)); + } + $qualifiedName = trim($qualifiedName); + try { return parent::createAttributeNS($namespaceURI, $qualifiedName); } catch (\DOMException $e) { @@ -62,6 +71,9 @@ class Document extends \DOMDocument { } public function createElement($name, $value = "") { + // Normalize the element name per modern DOM specifications. + $name = strtolower(trim($name)); + try { if ($name !== 'template') { $e = parent::createElement($name, $value); @@ -83,6 +95,13 @@ class Document extends \DOMDocument { } public function createElementNS($namespaceURI, $qualifiedName, $value = "") { + // Normalize the element name and namespace URI per modern DOM specifications. + if ($namespaceURI !== null) { + $namespaceURI = strtolower(trim($namespaceURI)); + $namespaceURI = ($namespaceURI === Parser::HTML_NAMESPACE) ? null : $namespaceURI; + } + $qualifiedName = trim($qualifiedName); + try { if ($qualifiedName !== 'template' || $namespaceURI !== null) { $e = parent::createElementNS($namespaceURI, $qualifiedName, $value); diff --git a/lib/DOM/Element.php b/lib/DOM/Element.php index a6cf4b1..8a4b868 100644 --- a/lib/DOM/Element.php +++ b/lib/DOM/Element.php @@ -63,6 +63,9 @@ class Element extends \DOMElement { } public function setAttribute($name, $value) { + // Normalize the attribute name per modern DOM specifications. + $name = strtolower(trim($name)); + // If setting a class attribute and classList has been invoked use classList to // set it. if ($name === 'class' && $this->_classList !== null) { @@ -85,6 +88,12 @@ class Element extends \DOMElement { } public function setAttributeNS($namespaceURI, $qualifiedName, $value) { + // Normalize the attribute name and namespace URI per modern DOM specifications. + if ($namespaceURI !== null) { + $namespaceURI = strtolower(trim($namespaceURI)); + } + $qualifiedName = trim($qualifiedName); + // If setting a class attribute and classList has been invoked use classList to // set it. if ($qualifiedName === 'class' && $namespaceURI === null && $this->_classList !== null) { diff --git a/lib/DOM/traits/Serialize.php b/lib/DOM/traits/Serialize.php index e0ed9ff..ae51d71 100644 --- a/lib/DOM/traits/Serialize.php +++ b/lib/DOM/traits/Serialize.php @@ -37,7 +37,7 @@ trait Serialize { # 3. If the node is a template element, then let the node instead be the # template element’s template contents (a DocumentFragment node). - if ($node instanceof Element && $node->nodeName === 'template') { + if ($node instanceof TemplateElement) { $node = $node->content; }