From ec5e540a9ad7ed0f6a09e674286c10f7175d7686 Mon Sep 17 00:00:00 2001 From: Sami Puro Date: Sat, 24 Oct 2026 17:10:41 +0300 Subject: [PATCH] Support unquoted href attributes in links --- src/Html2Text.php | 2 +- test/LinkTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Html2Text.php b/src/Html2Text.php index 6e0f9e5..dd2154e 100644 --- a/src/Html2Text.php +++ b/src/Html2Text.php @@ -145,7 +145,7 @@ class Html2Text '/<(strong)( [^>]*)?>(.*?)<\/strong>/i', // '/<(del)( [^>]*)?>(.*?)<\/del>/i', // '/<(th)( [^>]*)?>(.*?)<\/th>/i', // and - '/<(a) [^>]*href=("|\')([^"\']+)\2([^>]*)>(.*?)<\/a>/i' // + '/<(a) [^>]*href=(?|("|\')([^"\']+)\2|()([^\s"\'>]+))([^>]*)>(.*?)<\/a>/i' // and ); /** diff --git a/test/LinkTest.php b/test/LinkTest.php index 51ab635..5558d36 100644 --- a/test/LinkTest.php +++ b/test/LinkTest.php @@ -181,4 +181,14 @@ public function testMailtoWithEntity() $this->assertEquals($expected, $html2text->getText()); } + + public function testUnquotedHref() + { + $html = 'Link text and other'; + $expected = 'Link text [http://example.com/page?id=1] and other [/example.com]'; + + $html2text = new Html2Text($html, array('do_links' => 'inline')); + + $this->assertEquals($expected, $html2text->getText()); + } }