Skip to content

Commit

Permalink
Account for empty arrays in XMP data (#624)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Update Document.php

Remove blank line

---------

Co-authored-by: Konrad Abicht <[email protected]>
  • Loading branch information
GreyWyvern and k00ni authored Aug 7, 2023
1 parent f97e38c commit 053086a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Smalot/PdfParser/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 053086a

Please sign in to comment.