From 174f8ad2522742c32959a7af1883194d31a78d62 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Wed, 27 Sep 2023 22:30:45 +1000 Subject: [PATCH] Fixes to the libxml2 work around for the additional encoding of src, href, action & name attributes when calling saveHTML() method. --- src/Document.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Document.php b/src/Document.php index 474fed7..2d3cb52 100644 --- a/src/Document.php +++ b/src/Document.php @@ -225,7 +225,11 @@ public function saveHTML(?\DOMNode $node = null): string|false { $char = "'"; } - $search[] = $newName. '=' . $char . $value . $char; + // See xmlEscapeEntities() in: + // https://github.com/GNOME/libxml2/blob/master/xmlsave.c + $searchValue = str_replace(['<', '>', '&'], ['<', '>', '&'], $value); + + $search[] = $newName. '=' . $char . $searchValue . $char; $replace[] = $escape['attr']. '=' . $char . $value . $char; $i++;