]> BookStack Code Mirror - bookstack/commitdiff
Fixed old deprecated encoding convert on HTML doc load
authorDan Brown <redacted>
Thu, 23 Feb 2023 22:59:26 +0000 (22:59 +0000)
committerDan Brown <redacted>
Thu, 23 Feb 2023 22:59:26 +0000 (22:59 +0000)
app/Entities/Tools/PageContent.php
app/References/CrossLinkParser.php
app/Search/SearchIndex.php
app/Util/HtmlContentFilter.php

index 2613359c3afa67cf4f484d842abd1ffe2f9ea1a9..b4bc8b91b13cd680f3119822bd82b86ec9d67e6e 100644 (file)
@@ -449,8 +449,8 @@ class PageContent
     {
         libxml_use_internal_errors(true);
         $doc = new DOMDocument();
-        $html = '<body>' . $html . '</body>';
-        $doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
+        $html = '<?xml encoding="utf-8" ?><body>' . $html . '</body>';
+        $doc->loadHTML($html);
 
         return $doc;
     }
index 37db203df8f18fd7a9f2d498c8fe4546fa45daf3..e7afea5f1ffd1d16e03576afd1c5ee61b76a9da0 100644 (file)
@@ -54,10 +54,10 @@ class CrossLinkParser
     {
         $links = [];
 
-        $html = '<body>' . $html . '</body>';
+        $html = '<?xml encoding="utf-8" ?><body>' . $html . '</body>';
         libxml_use_internal_errors(true);
         $doc = new DOMDocument();
-        $doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
+        $doc->loadHTML($html);
 
         $xPath = new DOMXPath($doc);
         $anchors = $xPath->query('//a[@href]');
index 54ed95ebbe515f8aa322c2cbf405a7c7fbe99213..25389226a1ad5b1817c401fbef64adeb4044b743 100644 (file)
@@ -15,25 +15,18 @@ class SearchIndex
 {
     /**
      * A list of delimiter characters used to break-up parsed content into terms for indexing.
-     *
-     * @var string
      */
-    public static $delimiters = " \n\t.,!?:;()[]{}<>`'\"";
+    public static string $delimiters = " \n\t.,!?:;()[]{}<>`'\"";
 
-    /**
-     * @var EntityProvider
-     */
-    protected $entityProvider;
-
-    public function __construct(EntityProvider $entityProvider)
-    {
-        $this->entityProvider = $entityProvider;
+    public function __construct(
+        protected EntityProvider $entityProvider
+    ) {
     }
 
     /**
      * Index the given entity.
      */
-    public function indexEntity(Entity $entity)
+    public function indexEntity(Entity $entity): void
     {
         $this->deleteEntityTerms($entity);
         $terms = $this->entityToTermDataArray($entity);
@@ -45,7 +38,7 @@ class SearchIndex
      *
      * @param Entity[] $entities
      */
-    public function indexEntities(array $entities)
+    public function indexEntities(array $entities): void
     {
         $terms = [];
         foreach ($entities as $entity) {
@@ -69,7 +62,7 @@ class SearchIndex
      *
      * @param callable(Entity, int, int):void|null $progressCallback
      */
-    public function indexAllEntities(?callable $progressCallback = null)
+    public function indexAllEntities(?callable $progressCallback = null): void
     {
         SearchTerm::query()->truncate();
 
@@ -101,7 +94,7 @@ class SearchIndex
     /**
      * Delete related Entity search terms.
      */
-    public function deleteEntityTerms(Entity $entity)
+    public function deleteEntityTerms(Entity $entity): void
     {
         $entity->searchTerms()->delete();
     }
@@ -145,12 +138,12 @@ class SearchIndex
             'h6' => 1.5,
         ];
 
-        $html = '<body>' . $html . '</body>';
+        $html = '<?xml encoding="utf-8" ?><body>' . $html . '</body>';
         $html = str_ireplace(['<br>', '<br />', '<br/>'], "\n", $html);
 
         libxml_use_internal_errors(true);
         $doc = new DOMDocument();
-        $doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
+        $doc->loadHTML($html);
 
         $topElems = $doc->documentElement->childNodes->item(0)->childNodes;
         /** @var DOMNode $child */
index 5e3c4822c2e16a43c48da4c6f8a0edcbcf618746..e51f512bd1fe762d70928203f30be5efca1bbf5f 100644 (file)
@@ -19,10 +19,10 @@ class HtmlContentFilter
             return $html;
         }
 
-        $html = '<body>' . $html . '</body>';
+        $html = '<?xml encoding="utf-8" ?><body>' . $html . '</body>';
         libxml_use_internal_errors(true);
         $doc = new DOMDocument();
-        $doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
+        $doc->loadHTML($html);
         $xPath = new DOMXPath($doc);
 
         // Remove standard script tags