clean escaped json before logging

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2021-02-05 14:25:21 +01:00
parent d15b4f5070
commit 58fb001d1e
3 changed files with 11 additions and 7 deletions

View File

@ -392,6 +392,6 @@ It features background tasks and interactive chats, and can serve as an interfac
<p>@Gnadelwartz</p> <p>@Gnadelwartz</p>
<h2>That's it all guys!</h2> <h2>That's it all guys!</h2>
<p>If you feel that there's something missing or if you found a bug, feel free to submit a pull request!</p> <p>If you feel that there's something missing or if you found a bug, feel free to submit a pull request!</p>
<h4>$$VERSION$$ v1.40-dev-34-g1440d56</h4> <h4>$$VERSION$$ v1.40-0-gf9dab50</h4>
</body> </body>
</html> </html>

View File

@ -318,5 +318,5 @@ That's it all guys!
If you feel that there's something missing or if you found a bug, feel free to submit a If you feel that there's something missing or if you found a bug, feel free to submit a
pull request! pull request!
$$VERSION$$ v1.40-dev-34-g1440d56 $$VERSION$$ v1.40-0-gf9dab50

View File

@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb
# 8 - curl/wget missing # 8 - curl/wget missing
# 10 - not bash! # 10 - not bash!
# #
#### $$VERSION$$ v1.40-0-gf9dab50 #### $$VERSION$$ v1.41-dev-0-gd15b4f5
################################################################## ##################################################################
# are we running in a terminal? # are we running in a terminal?
@ -99,12 +99,16 @@ getConfigKey() {
[[ "$1" =~ ^[-${azAZo9},._]+$ ]] || return 3 [[ "$1" =~ ^[-${azAZo9},._]+$ ]] || return 3
[ -r "${BOTCONFIG}.jssh" ] && sed -n 's/\["'"$1"'"\]\t*"\(.*\)"/\1/p' "${BOTCONFIG}.jssh" | tail -n 1 [ -r "${BOTCONFIG}.jssh" ] && sed -n 's/\["'"$1"'"\]\t*"\(.*\)"/\1/p' "${BOTCONFIG}.jssh" | tail -n 1
} }
# escape / remove text characters for json strings, eg. " -> \" # escape characters in json strings for telegram
# $1 string # $1 string, output escaped string
# output escaped string
JsonEscape(){ JsonEscape(){
sed 's/\([-"`´,§$%&/(){}#@!?*.\t]\)/\\\1/g' <<< "$1" sed 's/\([-"`´,§$%&/(){}#@!?*.\t]\)/\\\1/g' <<< "$1"
} }
# clean \ from escaped json string
# $1 string, output cleaned string
cleanEscaped(){ # remove " all \ but \n \n or \r
sed -E -e 's/\\"/+/g' -e 's/\\([^n])/\1/g' -e 's/(\r|\n)//g' <<<"$1"
}
# check if $1 seems a valid token # check if $1 seems a valid token
# return true if token seems to be valid # return true if token seems to be valid
check_token(){ check_token(){
@ -461,7 +465,7 @@ sendJson(){
if [ -n "${BASHBOTDEBUG}" ] ; then if [ -n "${BASHBOTDEBUG}" ] ; then
log_update "sendJson (${DETECTED_CURL}) CHAT=${chat#*:} JSON=${2:0:100} URL=${3##*/}" log_update "sendJson (${DETECTED_CURL}) CHAT=${chat#*:} JSON=${2:0:100} URL=${3##*/}"
# mask " and \ , remove newline from json # mask " and \ , remove newline from json
log_message "DEBUG sendJson ==========\n$("${JSONSHFILE}" -b -n <<<"$(sed -E -e 's/\\"/+/g' -e 's/\\/\\\\/g' -e 's/(\r|\n)//g' <<<"${json}")" 2>&1)" log_message "DEBUG sendJson ==========\n$("${JSONSHFILE}" -b -n <<<"$(cleanEscaped "${json}")" 2>&1)"
fi fi
# chat id not a number # chat id not a number
if [[ "${chat}" == *"NAN\"," ]]; then if [[ "${chat}" == *"NAN\"," ]]; then