]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Fix: synchronous metadata retrieval is failing in strict mode 1664/head
authorArthurHoaro <arthur@hoa.ro>
Wed, 16 Dec 2020 13:04:32 +0000 (14:04 +0100)
committerArthurHoaro <arthur@hoa.ro>
Wed, 16 Dec 2020 13:04:32 +0000 (14:04 +0100)
Metadata can now only be string or null.

Fixes #1653

application/front/controller/admin/ShaarePublishController.php
application/http/MetadataRetriever.php
tests/http/MetadataRetrieverTest.php

index 4cbfcdc503f2abeaaefc839056949bfe337c2188..fb9cacc22fae47b3e9bc57cfe054292f4511b87d 100644 (file)
@@ -227,7 +227,7 @@ class ShaarePublishController extends ShaarliAdminController
 
     protected function buildFormData(array $link, bool $isNew, Request $request): array
     {
-        $link['tags'] = strlen($link['tags']) > 0
+        $link['tags'] = $link['tags'] !== null && strlen($link['tags']) > 0
             ? $link['tags'] . $this->container->conf->get('general.tags_separator', ' ')
             : $link['tags']
         ;
index 2e1401eca74f0c9857d7d31c34934a14b6811066..cfc72583e713a192f08199554388990d0d508f8b 100644 (file)
@@ -60,10 +60,15 @@ class MetadataRetriever
             $title = mb_convert_encoding($title, 'utf-8', $charset);
         }
 
-        return [
+        return array_map([$this, 'cleanMetadata'], [
             'title' => $title,
             'description' => $description,
             'tags' => $tags,
-        ];
+        ]);
+    }
+
+    protected function cleanMetadata($data): ?string
+    {
+        return !is_string($data) || empty(trim($data)) ? null : trim($data);
     }
 }
index 3c9eaa0e706a40803bee68a0a952028bd7c44e1c..cae65091f77c81c1bf01e837de3c20be8b4e245b 100644 (file)
@@ -41,7 +41,7 @@ class MetadataRetrieverTest extends TestCase
         $remoteCharset = 'utf-8';
 
         $expectedResult = [
-            'title' => $remoteTitle,
+            'title' => trim($remoteTitle),
             'description' => $remoteDesc,
             'tags' => $remoteTags,
         ];