Skip to content

Commit

Permalink
Fix HTML output in Bash 5.2 and newer
Browse files Browse the repository at this point in the history
As noted in testssl#2304, the way that the '&' character is treated in the string part of a pattern substitution changed in Bash 5.2. As a result, the change that was made in testssl#1481 to accommodate older versions of Bash (e.g., on MacOS) now causes testssl.sh to produce incorrect HTML output when run on Bash 5.2.

This commit encodes the '&' characters in the substitution strings in a way that produces correct results on multiple versions of Bash (3.2 on MacOS, 5.2 on Ubuntu 23.10, 5.0 on Ubuntu 20.04).
  • Loading branch information
dcooper16 committed Feb 3, 2023
1 parent cd2eef3 commit 5c0b831
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions testssl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,11 @@ html_reserved(){
local output
"$do_html" || return 0
#sed -e 's/\&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' -e 's/"/\&quot;/g' -e "s/'/\&apos;/g" <<< "$1"
output="${1//&/&amp;}"
output="${output//</&lt;}"
output="${output//>/&gt;}"
output="${output//\"/&quot;}"
output="${output//\'/&apos;}"
output="${1//&/$'&'amp;}"
output="${output//</$'&'lt;}"
output="${output//>/$'&'gt;}"
output="${output//\"/$'&'quot;}"
output="${output//\'/$'&'apos;}"
printf -- "%s" "$output"
return 0
}
Expand Down

0 comments on commit 5c0b831

Please sign in to comment.