Skip to content

Commit 41724b1

Browse files
authored
Don't assume newline after trailer marker, fixes #127 (#128)
1 parent 6e345cb commit 41724b1

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/Document/CrossReference/Table/CrossReferenceTableParser.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@ class CrossReferenceTableParser {
1919
public static function parse(Stream $stream, int $startPos, int $nrOfBytes): CrossReferenceSection {
2020
$startTrailerPos = $stream->firstPos(Marker::TRAILER, $startPos, $startPos + $nrOfBytes)
2121
?? throw new ParseFailureException('Unable to locate trailer for crossReferenceTable');
22-
$startDictionaryPos = $stream->firstPos(WhitespaceCharacter::LINE_FEED, $startTrailerPos, $startPos + $nrOfBytes)
23-
?? $stream->firstPos(WhitespaceCharacter::CARRIAGE_RETURN, $startTrailerPos, $startPos + $nrOfBytes)
24-
?? throw new ParseFailureException(sprintf('Expected a newline after %s, got none', Marker::TRAILER->value));
25-
$dictionary = DictionaryParser::parse($stream, $startDictionaryPos, $nrOfBytes - ($startDictionaryPos - $startPos));
22+
$dictionary = DictionaryParser::parse($stream, $startTrailerPos + Marker::TRAILER->length(), $nrOfBytes - ($startTrailerPos + Marker::TRAILER->length() - $startPos));
2623

2724
$objectNumber = $nrOfEntries = null;
2825
$crossReferenceSubSections = $crossReferenceEntries = [];
29-
$content = trim($stream->read($startPos, $startDictionaryPos - $startPos - strlen(Marker::TRAILER->value . PHP_EOL)));
26+
$content = trim($stream->read($startPos, $startTrailerPos - $startPos));
3027
$content = str_replace([WhitespaceCharacter::CARRIAGE_RETURN->value, WhitespaceCharacter::LINE_FEED->value . WhitespaceCharacter::LINE_FEED->value], WhitespaceCharacter::LINE_FEED->value, $content);
3128
foreach (explode(WhitespaceCharacter::LINE_FEED->value, $content) as $line) {
3229
$sections = explode(WhitespaceCharacter::SPACE->value, trim($line));

0 commit comments

Comments
 (0)