From 9df7b35c658c6ecbb5a5788d3d1b2c03c2dc6f6d Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 8 Dec 2021 12:49:13 +0200 Subject: [PATCH] DomIterator keys were off-by-one --- system/src/DOMLettersIterator.php | 2 +- system/src/DOMWordsIterator.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/system/src/DOMLettersIterator.php b/system/src/DOMLettersIterator.php index 3ebe20e4f..e3c2c4ad9 100644 --- a/system/src/DOMLettersIterator.php +++ b/system/src/DOMLettersIterator.php @@ -156,7 +156,7 @@ final class DOMLettersIterator implements Iterator { $this->current = $this->start; $this->offset = -1; - $this->key = -1; + $this->key = 0; $this->letters = []; $this->next(); diff --git a/system/src/DOMWordsIterator.php b/system/src/DOMWordsIterator.php index 31ca90fe9..fb7c2e374 100644 --- a/system/src/DOMWordsIterator.php +++ b/system/src/DOMWordsIterator.php @@ -28,7 +28,7 @@ final class DOMWordsIterator implements Iterator private $offset = -1; /** @var int|null */ private $key; - /** @var array|null */ + /** @var array>|null */ private $words; /** @@ -94,7 +94,7 @@ final class DOMWordsIterator implements Iterator if ($this->current->nodeType === XML_TEXT_NODE || $this->current->nodeType === XML_CDATA_SECTION_NODE) { if ($this->offset === -1) { - $this->words = preg_split("/[\n\r\t ]+/u", $this->current->textContent, -1, PREG_SPLIT_NO_EMPTY) ?: []; + $this->words = preg_split("/[\n\r\t ]+/", $this->current->textContent, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_OFFSET_CAPTURE) ?: []; } $this->offset++; @@ -133,7 +133,7 @@ final class DOMWordsIterator implements Iterator */ public function current(): ?string { - return $this->words ? $this->words[$this->offset] : null; + return $this->words ? (string)$this->words[$this->offset][0] : null; } /** @@ -150,7 +150,7 @@ final class DOMWordsIterator implements Iterator { $this->current = $this->start; $this->offset = -1; - $this->key = -1; + $this->key = 0; $this->words = []; $this->next();