diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-12-16 14:04:32 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-12-16 14:04:32 +0100 |
commit | 6a3a78d023aa320138bb88505b58347db268264a (patch) | |
tree | 127cbde2d900fb1cf9d2f5999941dfe3d79affbd | |
parent | e4b8330e459b598328bf250208386c06ec257b08 (diff) | |
download | Shaarli-6a3a78d023aa320138bb88505b58347db268264a.tar.gz Shaarli-6a3a78d023aa320138bb88505b58347db268264a.tar.zst Shaarli-6a3a78d023aa320138bb88505b58347db268264a.zip |
Fix: synchronous metadata retrieval is failing in strict mode
Metadata can now only be string or null.
Fixes #1653
-rw-r--r-- | application/front/controller/admin/ShaarePublishController.php | 2 | ||||
-rw-r--r-- | application/http/MetadataRetriever.php | 9 | ||||
-rw-r--r-- | tests/http/MetadataRetrieverTest.php | 2 |
3 files changed, 9 insertions, 4 deletions
diff --git a/application/front/controller/admin/ShaarePublishController.php b/application/front/controller/admin/ShaarePublishController.php index 4cbfcdc5..fb9cacc2 100644 --- a/application/front/controller/admin/ShaarePublishController.php +++ b/application/front/controller/admin/ShaarePublishController.php | |||
@@ -227,7 +227,7 @@ class ShaarePublishController extends ShaarliAdminController | |||
227 | 227 | ||
228 | protected function buildFormData(array $link, bool $isNew, Request $request): array | 228 | protected function buildFormData(array $link, bool $isNew, Request $request): array |
229 | { | 229 | { |
230 | $link['tags'] = strlen($link['tags']) > 0 | 230 | $link['tags'] = $link['tags'] !== null && strlen($link['tags']) > 0 |
231 | ? $link['tags'] . $this->container->conf->get('general.tags_separator', ' ') | 231 | ? $link['tags'] . $this->container->conf->get('general.tags_separator', ' ') |
232 | : $link['tags'] | 232 | : $link['tags'] |
233 | ; | 233 | ; |
diff --git a/application/http/MetadataRetriever.php b/application/http/MetadataRetriever.php index 2e1401ec..cfc72583 100644 --- a/application/http/MetadataRetriever.php +++ b/application/http/MetadataRetriever.php | |||
@@ -60,10 +60,15 @@ class MetadataRetriever | |||
60 | $title = mb_convert_encoding($title, 'utf-8', $charset); | 60 | $title = mb_convert_encoding($title, 'utf-8', $charset); |
61 | } | 61 | } |
62 | 62 | ||
63 | return [ | 63 | return array_map([$this, 'cleanMetadata'], [ |
64 | 'title' => $title, | 64 | 'title' => $title, |
65 | 'description' => $description, | 65 | 'description' => $description, |
66 | 'tags' => $tags, | 66 | 'tags' => $tags, |
67 | ]; | 67 | ]); |
68 | } | ||
69 | |||
70 | protected function cleanMetadata($data): ?string | ||
71 | { | ||
72 | return !is_string($data) || empty(trim($data)) ? null : trim($data); | ||
68 | } | 73 | } |
69 | } | 74 | } |
diff --git a/tests/http/MetadataRetrieverTest.php b/tests/http/MetadataRetrieverTest.php index 3c9eaa0e..cae65091 100644 --- a/tests/http/MetadataRetrieverTest.php +++ b/tests/http/MetadataRetrieverTest.php | |||
@@ -41,7 +41,7 @@ class MetadataRetrieverTest extends TestCase | |||
41 | $remoteCharset = 'utf-8'; | 41 | $remoteCharset = 'utf-8'; |
42 | 42 | ||
43 | $expectedResult = [ | 43 | $expectedResult = [ |
44 | 'title' => $remoteTitle, | 44 | 'title' => trim($remoteTitle), |
45 | 'description' => $remoteDesc, | 45 | 'description' => $remoteDesc, |
46 | 'tags' => $remoteTags, | 46 | 'tags' => $remoteTags, |
47 | ]; | 47 | ]; |