Skip to content

Commit

Permalink
check each slice if it's outside, not only first one
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Dec 14, 2021
1 parent 8c9f86c commit c2eded3
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/Tokenizer/Tokens.php
Expand Up @@ -858,13 +858,6 @@ public function insertSlices(array $slices): void
$this->setSize($oldSize + $itemsCount);

krsort($slices);

$firstIndex = array_key_first($slices);

if ($firstIndex > $oldSize) {
throw new \OutOfBoundsException('Cannot insert outside of collection.');
}

$insertBound = $oldSize - 1;

// since we only move already existing items around, we directly call into SplFixedArray::offset* methods.
Expand All @@ -874,6 +867,10 @@ public function insertSlices(array $slices): void
throw new \OutOfBoundsException(sprintf('Invalid index "%s".', $index));
}

if ($index > $oldSize) {
throw new \OutOfBoundsException(sprintf('Cannot insert index "%s" outside of collection.', $firstIndex));
}

$slice = \is_array($slice) || $slice instanceof self ? $slice : [$slice];
$sliceCount = \count($slice);

Expand Down

0 comments on commit c2eded3

Please sign in to comment.