From cd99b8c2ba46243750b7cd1d8fa0438a3d2ea7e9 Mon Sep 17 00:00:00 2001 From: Gustavo Arnosti Neves Date: Thu, 12 Apr 2018 06:39:14 -0300 Subject: [PATCH] v2.3.6 - fix grep detection method fail on some rare cases, would make execution fail instead of fail-safing --- pdfScale.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pdfScale.sh b/pdfScale.sh index 799ea1d..1e3a18e 100755 --- a/pdfScale.sh +++ b/pdfScale.sh @@ -12,7 +12,7 @@ # And: https://gist.github.com/MichaelJCole/86e4968dbfc13256228a -VERSION="2.3.5" +VERSION="2.3.6" ###################### EXTERNAL PROGRAMS ####################### @@ -1359,7 +1359,8 @@ getPageSizeCatGrep() { # Get MediaBox data if possible local mediaBox="$("$GREPBIN" -a -e '/MediaBox' -m 1 "$INFILEPDF" 2>/dev/null)" - mediaBox="${mediaBox##*/MediaBox}" + mediaBox="${mediaBox##*/MediaBox[}" + mediaBox="${mediaBox%%]*}" # No page size data available if isEmpty "$mediaBox" && isNotAdaptiveMode; then @@ -1369,18 +1370,18 @@ getPageSizeCatGrep() { fi # remove chars [ and ] - mediaBox="${mediaBox//[}" - mediaBox="${mediaBox//]}" + #mediaBox="${mediaBox//[}" + #mediaBox="${mediaBox//]}" mediaBox=($mediaBox) # make it an array mbCount=${#mediaBox[@]} # array size # sanity - if [[ $mbCount -lt 4 ]]; then - if isNotAdaptiveMode; then - notAdaptiveFailed $'Error when reading the page size!\nThe page size information is invalid!' - fi - return $FALSE + if [[ $mbCount -lt 4 ]] || ! isFloat "${mediaBox[2]}" || ! isFloat "${mediaBox[3]}"; then + if isNotAdaptiveMode; then + notAdaptiveFailed $'Error when reading the page size!\nThe page size information is invalid!' + fi + return $FALSE fi # we are done