From 98850bd475e6320beee9675ae1e40b1a603b87ba Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Thu, 28 Jul 2022 13:51:35 -0500 Subject: [PATCH] Fix possible infinite loop when building ebook carousel --- www/ebooks/ebook.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/www/ebooks/ebook.php b/www/ebooks/ebook.php index 7ff2910d..c47549a0 100644 --- a/www/ebooks/ebook.php +++ b/www/ebooks/ebook.php @@ -23,7 +23,6 @@ try{ // Ensure the path exists and that the root is in our www directory throw new Exceptions\InvalidEbookException(); } - // Were we passed the author and a work but not the translator? // For example: // https://standardebooks.org/ebooks/omar-khayyam/the-rubaiyat-of-omar-khayyam @@ -85,7 +84,9 @@ try{ shuffle($ebooks); $targetCarouselSize = 5; - if(sizeof($ebooks) < $targetCarouselSize){ + // Use <= here because we want to exclude the ebook we're looking at from the carousel. + // One of the matching ebooks will always be the current ebook. + if(sizeof($ebooks) <= $targetCarouselSize){ $targetCarouselSize = sizeof($ebooks) - 1; }