From ce6bdd79cf9967404b72bff99bcb49885c981ccc Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Mon, 22 Aug 2022 16:04:44 +0200 Subject: [PATCH] CI: json-common.sh - safety check + escape --- .github/scripts/json-common.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/scripts/json-common.sh b/.github/scripts/json-common.sh index c99193e2e..a5c280791 100644 --- a/.github/scripts/json-common.sh +++ b/.github/scripts/json-common.sh @@ -37,13 +37,15 @@ fetch_json() { echo "$JSON" } +is_int () { test "$@" -eq "$@"; } + ## @brief Checks HTTP error code for success ## @param $1 returned HTTP status code ## @param $2 (optional) returned JSON (to be printed in case of error) check_status() { - if [ $1 -lt 200 -o $1 -ge 300 ]; then + if ! is_int "$1" || [ "$1" -lt 200 ] || [ "$1" -ge 300 ]; then echo "Wrong response status $STATUS!" >&2 - if [ -n ${2-""} ]; then + if [ -n "${2-}" ]; then echo "JSON: $(cat $2)" >&2 fi exit 1