diff --git a/src/PdfParser/Type/PdfDictionary.php b/src/PdfParser/Type/PdfDictionary.php index 9f3aa30..f43dc07 100644 --- a/src/PdfParser/Type/PdfDictionary.php +++ b/src/PdfParser/Type/PdfDictionary.php @@ -48,14 +48,13 @@ public static function parse(Tokenizer $tokenizer, StreamReader $streamReader, P if (!($key instanceof PdfName)) { $lastToken = null; // ignore all other entries and search for the closing brackets - while (($token = $tokenizer->getNextToken()) !== '>' && $token !== false && $lastToken !== '>') { + while (($token = $tokenizer->getNextToken()) !== '>' || $lastToken !== '>') { + if ($token === false) { + return false; + } $lastToken = $token; } - if ($token === false) { - return false; - } - break; } diff --git a/src/PdfReader/PdfReader.php b/src/PdfReader/PdfReader.php index 95c4b7e..bcf2391 100644 --- a/src/PdfReader/PdfReader.php +++ b/src/PdfReader/PdfReader.php @@ -118,7 +118,6 @@ public function getPageCount() */ public function getPage($pageNumber) { - /** @phpstan-ignore function.alreadyNarrowedType */ if (!\is_numeric($pageNumber)) { throw new \InvalidArgumentException( 'Page number needs to be a number.' diff --git a/tests/functional/PdfParser/Type/PdfDictionaryTest.php b/tests/functional/PdfParser/Type/PdfDictionaryTest.php index bd7106e..a6a966a 100644 --- a/tests/functional/PdfParser/Type/PdfDictionaryTest.php +++ b/tests/functional/PdfParser/Type/PdfDictionaryTest.php @@ -29,6 +29,19 @@ public function parseProvider() 'A' => PdfString::create('hello') ]) ], + [ + '/A (hello) B [<>]>>', + PdfDictionary::create([ + 'A' => PdfString::create('hello') + ]) + ], + // this faulty structure is currently not handled +// [ +// '/A (hello) B [<<>>]>>', +// PdfDictionary::create([ +// 'A' => PdfString::create('hello') +// ]) +// ], [ '/A (1) /B (2) /C <> >>', PdfDictionary::create([ @@ -120,8 +133,8 @@ public function testParse($in, $expectedResult) $result = PdfDictionary::parse($tokenizer, $stream, $parser); $this->assertInstanceOf(PdfDictionary::class, $result); - $this->assertEquals($expectedResult->value, $result->value); + $this->assertFalse($tokenizer->getNextToken()); } public function testParseBehind()