diff --git a/src/Document/Dictionary/DictionaryParser.php b/src/Document/Dictionary/DictionaryParser.php index 8568d07..67d4337 100644 --- a/src/Document/Dictionary/DictionaryParser.php +++ b/src/Document/Dictionary/DictionaryParser.php @@ -74,6 +74,9 @@ public static function parse(?EncryptionContext $encryptionContext, Stream $stre } elseif (trim($char) !== '' && $nestingContext->getContext() === DictionaryParseContext::KEY_VALUE_SEPARATOR) { $nestingContext->setContext(DictionaryParseContext::VALUE); } elseif ($char === DelimiterCharacter::PERCENT_SIGN->value && $rollingCharBuffer->getPreviousCharacter() !== LiteralStringEscapeCharacter::REVERSE_SOLIDUS->value && $nestingContext->getContext() !== DictionaryParseContext::VALUE_IN_PARENTHESES) { + if ($nestingContext->getContext() === DictionaryParseContext::VALUE) { + self::flush($dictionaryArray, $nestingContext); + } $nestingContext->setContext(DictionaryParseContext::COMMENT); } diff --git a/tests/Unit/Document/Dictionary/DictionaryParserTest.php b/tests/Unit/Document/Dictionary/DictionaryParserTest.php index 9940229..a5e5d2c 100644 --- a/tests/Unit/Document/Dictionary/DictionaryParserTest.php +++ b/tests/Unit/Document/Dictionary/DictionaryParserTest.php @@ -421,4 +421,23 @@ public function testHandlesValueOnNewLine(): void { DictionaryParser::parse(null, $stream, 0, $stream->getSizeInBytes()), ); } + + public function testHandlesKeyValuePairWithTrailingComments(): void { + $stream = new InMemoryStream( + <<> + EOD, + ); + static::assertEquals( + new Dictionary( + new DictionaryEntry(DictionaryKey::TYPE, TypeNameValue::CATALOG), + new DictionaryEntry(DictionaryKey::PAGES, new ReferenceValue(3, 0)), + ), + DictionaryParser::parse(null, $stream, 0, $stream->getSizeInBytes()), + ); + } }