Skip to content

Commit

Permalink
Account for empty arrays in XMP data
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
GreyWyvern committed Aug 2, 2023
1 parent ce434c1 commit be13a68
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/Smalot/PdfParser/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,21 @@ 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];

// else if the value is an empty array, set
// the value of this property to the empty
// string
} elseif (0 == \count($metadata)) {
$metadata = '';
}
}

// Move down one level in the stack
Expand Down

0 comments on commit be13a68

Please sign in to comment.