Merge pull request #1664 from ArthurHoaro/fix/metadata-sync

Fix: synchronous metadata retrieval is failing in strict mode
This commit is contained in:
ArthurHoaro 2020-12-29 11:44:10 +01:00 committed by GitHub
commit fe58bdcd9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 4 deletions

View file

@ -227,7 +227,7 @@ class ShaarePublishController extends ShaarliAdminController
protected function buildFormData(array $link, bool $isNew, Request $request): array 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'] . $this->container->conf->get('general.tags_separator', ' ')
: $link['tags'] : $link['tags']
; ;

View file

@ -60,10 +60,15 @@ class MetadataRetriever
$title = mb_convert_encoding($title, 'utf-8', $charset); $title = mb_convert_encoding($title, 'utf-8', $charset);
} }
return [ return array_map([$this, 'cleanMetadata'], [
'title' => $title, 'title' => $title,
'description' => $description, 'description' => $description,
'tags' => $tags, 'tags' => $tags,
]; ]);
}
protected function cleanMetadata($data): ?string
{
return !is_string($data) || empty(trim($data)) ? null : trim($data);
} }
} }

View file

@ -41,7 +41,7 @@ class MetadataRetrieverTest extends TestCase
$remoteCharset = 'utf-8'; $remoteCharset = 'utf-8';
$expectedResult = [ $expectedResult = [
'title' => $remoteTitle, 'title' => trim($remoteTitle),
'description' => $remoteDesc, 'description' => $remoteDesc,
'tags' => $remoteTags, 'tags' => $remoteTags,
]; ];