From 053086a22244ba91e1f454d84103ea9069bb8996 Mon Sep 17 00:00:00 2001 From: Brian Huisman Date: Mon, 7 Aug 2023 02:41:36 -0400 Subject: [PATCH] Account for empty arrays in XMP data (#624) * Account for empty arrays in XMP data The previous version of Document::extractXMPMetadata() did not account for empty arrays as values. When encountered, use the empty string as a value for this property. * Update src/Smalot/PdfParser/Document.php Co-authored-by: Konrad Abicht * Update Document.php Remove blank line --------- Co-authored-by: Konrad Abicht --- src/Smalot/PdfParser/Document.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Smalot/PdfParser/Document.php b/src/Smalot/PdfParser/Document.php index d2cec38e..8412eed8 100644 --- a/src/Smalot/PdfParser/Document.php +++ b/src/Smalot/PdfParser/Document.php @@ -263,12 +263,20 @@ public function extractXMPMetadata(string $content): void break; case 'close': - // If the value of this property is a single- - // element array where the element is of type - // string, use the value of the first list item - // as the value for this property - if (\is_array($metadata) && isset($metadata[0]) && 1 == \count($metadata) && \is_string($metadata[0])) { - $metadata = $metadata[0]; + // If the value of this property is an array + if (\is_array($metadata)) { + // If the value is a single element array + // where the element is of type string, use + // the value of the first list item as the + // value for this property + if (1 == \count($metadata) && isset($metadata[0]) && \is_string($metadata[0])) { + $metadata = $metadata[0]; + } elseif (0 == \count($metadata)) { + // if the value is an empty array, set + // the value of this property to the empty + // string + $metadata = ''; + } } // Move down one level in the stack