Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/Document/ContentStream/ContentStreamParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static function parse(array $contentsObjects): ContentStream {
for ($index = 0; $index < $contentStreamSize; $index++) {
$char = $contentStream->read($index, 1);
if ($inComment === true) {
if (in_array($char, ["\r", "\n"], true)) {
if ($char === "\r" || $char === "\n") {
$endCommentOffset = $index + 1;
$inComment = false;
}
Expand All @@ -52,7 +52,7 @@ public static function parse(array $contentsObjects): ContentStream {
$inStringLiteral = false;
}
} elseif ($inResourceName === true) {
if (in_array($char, [' ', '<', '(', '/', "\r", "\n"], true) && $previousChar !== '\\') {
if ($previousChar !== '\\' && ($char === ' ' || $char === '<' || $char === '(' || $char === '/' || $char === "\r" || $char === "\n")) {
$inResourceName = false;
}
} elseif ($inDictionary === true) {
Expand Down Expand Up @@ -98,9 +98,10 @@ public static function parse(array $contentsObjects): ContentStream {
$operands .= $previousContentStream->read($startPreviousOperandIndex, $previousContentStream->getSizeInBytes() - $startPreviousOperandIndex);
$startPreviousOperandIndex = null;
}
$operandLength = $index + 1 - $startCurrentOperandIndex - strlen($operator->value);
$operatorLength = strlen($operator->value);
$operandLength = $index + 1 - $startCurrentOperandIndex - $operatorLength;
if ($operandLength > 0) {
$operandEndOffset = $index + 1 - strlen($operator->value);
$operandEndOffset = $index + 1 - $operatorLength;
if ($endCommentOffset !== null
&& $endCommentOffset < $operandEndOffset
&& $startOfCommentOffset !== null
Expand Down Expand Up @@ -149,7 +150,7 @@ public static function getOperator(string $currentChar, ?string $previousChar, ?
default => null,
};
if ($threeLetterMatch !== null) {
return in_array($thirdToLastChar, ['\\', '/'], true) ? null : $threeLetterMatch;
return ($thirdToLastChar === '\\' || $thirdToLastChar === '/') ? null : $threeLetterMatch;
}

$twoLetterMatch = match ($previousChar . $currentChar) {
Expand Down Expand Up @@ -195,7 +196,7 @@ public static function getOperator(string $currentChar, ?string $previousChar, ?
default => null,
};
if ($twoLetterMatch !== null) {
return in_array($secondToLastChar, ['\\', '/'], true) ? null : $twoLetterMatch;
return ($secondToLastChar === '\\' || $secondToLastChar === '/') ? null : $twoLetterMatch;
}

$oneLetterMatch = match ($currentChar) {
Expand Down Expand Up @@ -230,7 +231,7 @@ public static function getOperator(string $currentChar, ?string $previousChar, ?
};

if ($oneLetterMatch !== null) {
return in_array($previousChar, ['\\', '/'], true) ? null : $oneLetterMatch;
return ($previousChar === '\\' || $previousChar === '/') ? null : $oneLetterMatch;
}

return null;
Expand Down
Loading