diff --git a/src/Document/Dictionary/DictionaryValue/Array/ArrayValue.php b/src/Document/Dictionary/DictionaryValue/Array/ArrayValue.php index 187b7b6a..4a576735 100644 --- a/src/Document/Dictionary/DictionaryValue/Array/ArrayValue.php +++ b/src/Document/Dictionary/DictionaryValue/Array/ArrayValue.php @@ -32,8 +32,11 @@ public static function fromValue(string $valueString): self|ReferenceValueArray| $sanitizedValueString = preg_replace('/\s+/', ' ', $sanitizedValueString) ?? throw new RuntimeException('An error occurred while removing duplicate spaces from array value'); $values = explode(' ', $sanitizedValueString); - if (count($values) % 3 === 0 && array_key_exists(2, $values) && $values[2] === 'R') { - return ReferenceValueArray::fromValue($valueString); + if (count($values) % 3 === 0 + && array_key_exists(2, $values) + && $values[2] === 'R' + && ($referenceValueArray = ReferenceValueArray::fromValue($valueString)) !== null) { + return $referenceValueArray; } $array = []; diff --git a/tests/Unit/Document/Dictionary/DictionaryValue/Array/ArrayValueTest.php b/tests/Unit/Document/Dictionary/DictionaryValue/Array/ArrayValueTest.php index 62da3530..075c000b 100644 --- a/tests/Unit/Document/Dictionary/DictionaryValue/Array/ArrayValueTest.php +++ b/tests/Unit/Document/Dictionary/DictionaryValue/Array/ArrayValueTest.php @@ -54,6 +54,14 @@ public function testFromValue(): void { new ReferenceValueArray(new ReferenceValue(42, 0), new ReferenceValue(43, 0)), ArrayValue::fromValue('[42 0 R 43 0 R]'), ); + static::assertEquals( + new ArrayValue(['459', '0', 'R', '/FitH', '10000']), + ArrayValue::fromValue( + <<