Make JSON more robust
In cases where a finding was empty (error condition), the JSON output wasn't valid because the finding wasn't printed to file. This commit makes sure that always a finding is printed, also if it is empty. FIX #1112
This commit is contained in:
parent
1bfc9ca5b8
commit
a24a502716
30
testssl.sh
30
testssl.sh
|
@ -738,25 +738,25 @@ fileout_section_header() {
|
||||||
|
|
||||||
# arg1: whether to end object too
|
# arg1: whether to end object too
|
||||||
fileout_section_footer() {
|
fileout_section_footer() {
|
||||||
"$do_pretty_json" && printf "\n ]" >> "$JSONFILE"
|
"$do_pretty_json" && printf "\n ]" >> "$JSONFILE"
|
||||||
"$do_pretty_json" && "$1" && echo -e "\n }" >> "$JSONFILE"
|
"$do_pretty_json" && "$1" && echo -e "\n }" >> "$JSONFILE"
|
||||||
SECTION_FOOTER_NEEDED=false
|
SECTION_FOOTER_NEEDED=false
|
||||||
}
|
}
|
||||||
|
|
||||||
fileout_json_print_parameter() {
|
fileout_json_print_parameter() {
|
||||||
local parameter="$1"
|
local parameter="$1"
|
||||||
local filler="$2"
|
local filler="$2"
|
||||||
local value="$3"
|
local value="$3"
|
||||||
local not_last="$4"
|
local not_last="$4"
|
||||||
local spaces=""
|
local spaces=""
|
||||||
|
|
||||||
"$do_json" && \
|
"$do_json" && \
|
||||||
spaces=" " || \
|
spaces=" " || \
|
||||||
spaces=" "
|
spaces=" "
|
||||||
if [[ ! -z "$value" ]]; then
|
if [[ -n "$value" ]] || [[ "$parameter" == finding ]]; then
|
||||||
printf "%s%s%s%s" "$spaces" "\"$parameter\"" "$filler" ": \"$value\"" >> "$JSONFILE"
|
printf "%s%s%s%s" "$spaces" "\"$parameter\"" "$filler" ": \"$value\"" >> "$JSONFILE"
|
||||||
"$not_last" && printf ",\n" >> "$JSONFILE"
|
"$not_last" && printf ",\n" >> "$JSONFILE"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
fileout_json_finding() {
|
fileout_json_finding() {
|
||||||
|
|
Loading…
Reference in New Issue