diff options
-rw-r--r-- | src/HTML5/Serializer/OutputRules.php | 5 | ||||
-rw-r--r-- | test/HTML5/Serializer/OutputRulesTest.php | 22 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/HTML5/Serializer/OutputRules.php b/src/HTML5/Serializer/OutputRules.php index 862ab55..79b14b5 100644 --- a/src/HTML5/Serializer/OutputRules.php +++ b/src/HTML5/Serializer/OutputRules.php @@ -158,7 +158,10 @@ class OutputRules implements \HTML5\Serializer\RulesInterface { $name = Elements::normalizeMathMlAttribute($name); } - $this->wr(' ')->wr($name)->wr('="')->wr($val)->wr('"'); + $this->wr(' ')->wr($name); + if (!empty($val)) { + $this->wr('="')->wr($val)->wr('"'); + } } } diff --git a/test/HTML5/Serializer/OutputRulesTest.php b/test/HTML5/Serializer/OutputRulesTest.php index 70d3b7d..b6a53c6 100644 --- a/test/HTML5/Serializer/OutputRulesTest.php +++ b/test/HTML5/Serializer/OutputRulesTest.php @@ -205,6 +205,28 @@ class OutputRulesTest extends \HTML5\Tests\TestCase { $this->assertEquals('.+#', $m->invoke($o, '.+#')); } + function testAttrs() { + $dom = \HTML5::loadHTML('<!doctype html> + <html lang="en"> + <body> + <div id="foo" class="bar baz" disabled>foo bar baz</div> + </body> + </html>'); + + $stream = fopen('php://temp', 'w'); + $t = new Traverser($dom, $stream, \HTML5::options()); + $p = $this->getTraverserProtectedProperty('rules'); + $o = $p->getValue($t); + + $list = $dom->getElementsByTagName('div'); + + $m = $this->getProtectedMethod('attrs'); + $m->invoke($o, $list->item(0)); + + $content = stream_get_contents($stream, -1, 0); + $this->assertEquals(' id="foo" class="bar baz" disabled', $content); + } + function testSvg() { $dom = \HTML5::loadHTML('<!doctype html> <html lang="en"> |