Skip to content

Commit 092e4b9

Browse files
committed
fix: ensure before_script and/or after_script are non-empty before attempting to cast to array
Bash's `readarray` will fail if a value is an empty string. As such, we need to test that the value returned from `jq` is not empty before attempting to create an array from it. Additionally, newlines can cause issues, so this adds logic to strip all newlines. Signed-off-by: Matthew Weier O'Phinney <[email protected]>
1 parent 0d0c2b5 commit 092e4b9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

entrypoint.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,18 @@ if [[ "${PHP}" == "" ]];then
142142
fi
143143

144144
declare -a BEFORE_SCRIPT=()
145-
readarray -t BEFORE_SCRIPT="$(echo "${JOB}" | jq -rc '(.before_script // [])[]' )"
145+
BEFORE_SCRIPT_STRING="$(echo "${JOB}" | jq -rc '(.before_script // [])[]' | tr -d '\n')"
146+
echo "BEFORE_SCRIPT: ${BEFORE_SCRIPT_STRING}"
147+
if [[ "${BEFORE_SCRIPT_STRING}" != "" ]]; then
148+
readarray -t BEFORE_SCRIPT="${BEFORE_SCRIPT_STRING}"
149+
fi
146150

147151
declare -a AFTER_SCRIPT=()
148-
readarray -t AFTER_SCRIPT="$(echo "${JOB}" | jq -rc '(.after_script // [])[]' )"
152+
AFTER_SCRIPT_STRING="$(echo "${JOB}" | jq -rc '(.after_script // [])[]' | tr -d '\n')"
153+
echo "AFTER_SCRIPT: ${AFTER_SCRIPT_STRING}"
154+
if [[ "${AFTER_SCRIPT_STRING}" != "" ]]; then
155+
readarray -t AFTER_SCRIPT="${AFTER_SCRIPT_STRING}"
156+
fi
149157

150158

151159
echo "Marking PHP ${PHP} as configured default"

0 commit comments

Comments
 (0)