Skip to content

Commit a2633d9

Browse files
authored
Merge pull request #263 from eyupcanakman/fix/fwrite-null-deprecation-254
Fix fwrite() null deprecation in OutputRules::wr() on PHP 8.1+
2 parents fcf91eb + 6160434 commit a2633d9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/HTML5/Serializer/OutputRules.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ protected function closeTag($ele)
454454
*/
455455
protected function wr($text)
456456
{
457-
fwrite($this->out, $text);
457+
fwrite($this->out, (string) $text);
458458

459459
return $this;
460460
}

test/HTML5/Serializer/OutputRulesTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,16 @@ public function testWr()
382382
$this->assertEquals('foo', stream_get_contents($s, -1, 0));
383383
}
384384

385+
public function testWrWithNullNodeValue()
386+
{
387+
// Namespace nodes with an empty URI (xmlns:w="") can expose a null nodeValue; verify no error on serialization.
388+
$this->html5 = $this->getInstance(array('xmlNamespaces' => true));
389+
$input = '<!doctype html><html><body><span xmlns:w="" data-x="1"></span></body></html>';
390+
$dom = $this->html5->loadHTML($input);
391+
$result = $this->html5->saveHTML($dom);
392+
$this->assertTrue(false !== strpos($result, 'xmlns:w=""'));
393+
}
394+
385395
public function getEncData()
386396
{
387397
return array(

0 commit comments

Comments
 (0)