danog / MadelineProto

Async PHP client API for the telegram MTProto protocol
https://docs.madelineproto.xyz
GNU Affero General Public License v3.0
2.76k stars 619 forks source link

Fix error - Argument #1 ($node) must be of type DOMNode|DOMText #1437

Closed DamienDie closed 8 months ago

DamienDie commented 8 months ago

Text HTML: Text send text <a href="https://sitetest2.top/L?tag=s_12695m_124c_&site=12689&ad=1234">link</a> dev <a href="https://sitetest3.top/site=126895&ad=1234">link2</a>

$message = 'Text send text <a href="https://sitetest2.top/L?tag=s_12695m_124c_&site=12689&ad=1234">link</a> dev <a href="https://sitetest3.top/site=126895&ad=1234">link2</a>'
$result = $this->htmlToMessageEntities($message);

An error appears when calling function: htmlToMessageEntities($message)

Error:

\danog\MadelineProto\Exception: An error occurred while parsing Text send text link dev link2: danog\MadelineProto\TL\Conversion\DOMEntities::parseNode(): Argument #1 ($node) must be of type DOMNode|DOMText, null given, called in /var/www/html/vendor/danog/madelineproto/src/TL/Conversion/DOMEntities.php on line 48 in /var/www/html/vendor/danog/madelineproto/src/TL/Conversion/DOMEntities.php:52

When sending pure html, the same error occurs, with the parse_mode=HTML option without entities $this->messages->sendMessage()

danog commented 8 months ago

Escape the URL to fix:

$message = 'Text send text <a href="https://sitetest2.top/L?tag=s_12695m_124c_&amp;site=12689&amp;ad=1234">link</a> dev <a href="https://sitetest3.top/site=126895&amp;ad=1234">link2</a>';