diff --git a/lib/DOM/Document.php b/lib/DOM/Document.php index b13bb3e..9c1bd12 100644 --- a/lib/DOM/Document.php +++ b/lib/DOM/Document.php @@ -76,7 +76,7 @@ class Document extends \DOMDocument { try { if ($name !== 'template') { - $e = parent::createElement($name, $value); + $e = parent::createElementNS(null, $name, $value); } else { $e = new TemplateElement($this, $name, $value); $this->templateElements[] = $e; @@ -90,7 +90,7 @@ class Document extends \DOMDocument { // uppercase hexadecimal digits of the character's code point $this->mangledElements = true; $name = $this->coerceName($name); - return parent::createElement($name, $value); + return parent::createElementNS(null, $name, $value); } } diff --git a/tests/cases/TestDOM.php b/tests/cases/TestDOM.php index cfdad31..4bfb48c 100644 --- a/tests/cases/TestDOM.php +++ b/tests/cases/TestDOM.php @@ -44,4 +44,21 @@ class TestDOM extends \PHPUnit\Framework\TestCase { ["http://www.w3.org/1998/Math/MathML", "TEST", "http://www.w3.org/1998/Math/MathML", "TEST", ""], ]; } + /** @dataProvider provideBareElements */ + public function testCreateBareElements(string $nameIn, $nameOut): void { + $d = new Document; + $e = $d->createElement($nameIn); + $this->assertNull($e->namespaceURI); + $this->assertSame("", $e->prefix); + $this->assertSame($nameOut, $e->localName); + } + + public function provideBareElements(): iterable { + return [ + ["test", "test"], + ["test:test", "testU00003Atest"], + ["9", "U000039"], + ["TEST", "test"], + ]; + } }