From 863c6f9b1d07e8751fffb117088a5d0b5cef681c Mon Sep 17 00:00:00 2001 From: AC Date: Tue, 20 Oct 2026 14:14:46 +0800 Subject: [PATCH] Preserve form feeds in quoted attribute values --- src/HTML5/Parser/Tokenizer.php | 2 +- test/HTML5/Html5Test.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/HTML5/Parser/Tokenizer.php b/src/HTML5/Parser/Tokenizer.php index 653903c..17a3052 100644 --- a/src/HTML5/Parser/Tokenizer.php +++ b/src/HTML5/Parser/Tokenizer.php @@ -567,7 +567,7 @@ protected function attributeValue() */ protected function quotedAttributeValue($quote) { - $stoplist = "\f" . $quote; + $stoplist = $quote; $val = ''; while (true) { diff --git a/test/HTML5/Html5Test.php b/test/HTML5/Html5Test.php index 0fd307e..3c267e2 100644 --- a/test/HTML5/Html5Test.php +++ b/test/HTML5/Html5Test.php @@ -38,6 +38,38 @@ protected function cycleFragment($fragment) return $out; } + public function testFormFeedsInQuotedAttributes() + { + foreach (array('"', "'") as $quote) { + $value = "\fbefore &\f after\f"; + $html = ' . $quote . $value . $quote . '; + $expected = "\fbefore &\f after\f"; + + $document = $this->html5->loadHTML($this->wrap($html)); + $image = $document->getElementsByTagName('img')->item(0); + $this->assertSame($expected, $image->getAttribute('alt')); + $this->assertSame('foo.png', $image->getAttribute('src')); + $this->assertSame(2, $image->attributes->length); + $this->assertEmpty($this->html5->getErrors()); + + $fragment = $this->html5->loadHTMLFragment($html); + $this->assertSame($expected, $fragment->firstChild->getAttribute('alt')); + $serialized = $this->html5->saveHTML($fragment); + $reparsed = $this->html5->loadHTMLFragment($serialized); + $this->assertSame($expected, $reparsed->firstChild->getAttribute('alt')); + $this->assertSame('foo.png', $reparsed->firstChild->getAttribute('src')); + $this->assertEmpty($this->html5->getErrors()); + } + } + + public function testFormFeedStillSeparatesUnquotedAttributes() + { + $fragment = $this->html5->loadHTMLFragment("before\fsrc=foo.png"); + $this->assertSame('before', $fragment->firstChild->getAttribute('alt')); + $this->assertSame('foo.png', $fragment->firstChild->getAttribute('src')); + $this->assertEmpty($this->html5->getErrors()); + } + public function testImageTagsInSvg() { $html = '