From dfbc29811fa5f6fd1d7541bf2d095f85f28d5bba Mon Sep 17 00:00:00 2001 From: EthanHealy01 Date: Wed, 17 Sep 2025 20:39:36 +0100 Subject: [PATCH] regex was broken --- .../tools/removePages/useRemovePagesOperation.ts | 3 ++- frontend/src/utils/pageSelection.ts | 12 +++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/frontend/src/hooks/tools/removePages/useRemovePagesOperation.ts b/frontend/src/hooks/tools/removePages/useRemovePagesOperation.ts index 361109794..95296fd07 100644 --- a/frontend/src/hooks/tools/removePages/useRemovePagesOperation.ts +++ b/frontend/src/hooks/tools/removePages/useRemovePagesOperation.ts @@ -7,7 +7,8 @@ import { RemovePagesParameters, defaultParameters } from './useRemovePagesParame export const buildRemovePagesFormData = (parameters: RemovePagesParameters, file: File): FormData => { const formData = new FormData(); formData.append('fileInput', file); - formData.append('pageNumbers', parameters.pageNumbers); + const cleaned = parameters.pageNumbers.replace(/\s+/g, ''); + formData.append('pageNumbers', cleaned); return formData; }; diff --git a/frontend/src/utils/pageSelection.ts b/frontend/src/utils/pageSelection.ts index 9684d9609..4909581bb 100644 --- a/frontend/src/utils/pageSelection.ts +++ b/frontend/src/utils/pageSelection.ts @@ -6,20 +6,18 @@ export const validatePageNumbers = (pageNumbers: string): boolean => { const parts = normalized.split(','); // Regular expressions for different page number formats - const singlePageRegex = /^\d+$/; // Single page: 1, 2, 3, etc. - const rangeRegex = /^\d+-\d*$/; // Range: 1-5, 10-, etc. - const negativeRegex = /^-\d+$/; // Negative: -3 (last 3 pages) - const mathRegex = /^\d*[n]\d*[+\-*/]\d+$/; // Mathematical: 2n+1, n-1, etc. + const allToken = /^all$/i; // Select all pages + const singlePageRegex = /^[1-9]\d*$/; // Single page: positive integers only (no 0) + const rangeRegex = /^[1-9]\d*-(?:[1-9]\d*)?$/; // Range: 1-5 or open range 10- + const mathRegex = /^(?=.*n)[0-9n+\-*/() ]+$/; // Mathematical expressions with n and allowed chars return parts.every(part => { if (!part) return false; return ( + allToken.test(part) || singlePageRegex.test(part) || rangeRegex.test(part) || - negativeRegex.test(part) || mathRegex.test(part) ); }); }; - -