Fix the handling of multiple images
authorAlexander Ebert <ebert@woltlab.com>
Thu, 15 Aug 2024 11:03:48 +0000 (13:03 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 15 Aug 2024 11:03:48 +0000 (13:03 +0200)
`getElementsByTagName()` is a live collection, removing items mutates the underlying data structure hence the iterator will no longer work as expected.

wcfsetup/install/files/lib/system/background/job/ServiceWorkerDeliveryBackgroundJob.class.php

index 3cdd7da3a3bfe7ab28db505779bee61cbaec7259..cdc51a228c328f440a7058b68801b5e76a7b6817 100644 (file)
@@ -141,7 +141,10 @@ final class ServiceWorkerDeliveryBackgroundJob extends AbstractUniqueBackgroundJ
         \libxml_clear_errors();
         \libxml_use_internal_errors($useInternalErrors);
 
-        foreach ($document->getElementsByTagName('img') as $image) {
+        $images = $document->getElementsByTagName('img');
+        while ($images->length > 0) {
+            $image = $images->item(0);
+
             \assert($image instanceof \DOMElement);
             $image->replaceWith($image->getAttribute('alt'));
         }