From bdcccfd93790767850af8c58542d867e28c4f21f Mon Sep 17 00:00:00 2001 From: Ludy Date: Mon, 4 Mar 2024 21:14:45 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix:=20`index=20out=20of=20bound?= =?UTF-8?q?s`=20#861=20#842=20(#863)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐛 Fix: `index out of bounds` #861 #842 * Update RearrangePagesPDFController.java * Update RearrangePagesPDFController.java --- .../SPDF/controller/api/RearrangePagesPDFController.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/controller/api/RearrangePagesPDFController.java b/src/main/java/stirling/software/SPDF/controller/api/RearrangePagesPDFController.java index 88bdcd91..f6170485 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/RearrangePagesPDFController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/RearrangePagesPDFController.java @@ -2,6 +2,7 @@ package stirling.software.SPDF.controller.api; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.apache.pdfbox.Loader; @@ -50,7 +51,9 @@ public class RearrangePagesPDFController { String[] pageOrderArr = pagesToDelete.split(","); List pagesToRemove = - GeneralUtils.parsePageList(pageOrderArr, document.getNumberOfPages()); + GeneralUtils.parsePageList(pageOrderArr, document.getNumberOfPages(), true); + + Collections.sort(pagesToRemove); for (int i = pagesToRemove.size() - 1; i >= 0; i--) { int pageIndex = pagesToRemove.get(i); @@ -192,7 +195,7 @@ public class RearrangePagesPDFController { if (sortType != null && sortType.length() > 0) { newPageOrder = processSortTypes(sortType, totalPages); } else { - newPageOrder = GeneralUtils.parsePageList(pageOrderArr, totalPages); + newPageOrder = GeneralUtils.parsePageList(pageOrderArr, totalPages, true); } logger.info("newPageOrder = " + newPageOrder); logger.info("totalPages = " + totalPages);