From 58fb001d1e4f3b68a1fe796b799059e12a365897 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 5 Feb 2021 14:25:21 +0100 Subject: [PATCH] clean escaped json before logging --- README.html | 2 +- README.txt | 2 +- bashbot.sh | 14 +++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/README.html b/README.html index a51e2cb..7afb288 100644 --- a/README.html +++ b/README.html @@ -392,6 +392,6 @@ It features background tasks and interactive chats, and can serve as an interfac

@Gnadelwartz

That's it all guys!

If you feel that there's something missing or if you found a bug, feel free to submit a pull request!

-

$$VERSION$$ v1.40-dev-34-g1440d56

+

$$VERSION$$ v1.40-0-gf9dab50

diff --git a/README.txt b/README.txt index 9d6fbcb..c9150f8 100644 --- a/README.txt +++ b/README.txt @@ -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 pull request! -$$VERSION$$ v1.40-dev-34-g1440d56 +$$VERSION$$ v1.40-0-gf9dab50 diff --git a/bashbot.sh b/bashbot.sh index 404fad6..588619b 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.40-0-gf9dab50 +#### $$VERSION$$ v1.41-dev-0-gd15b4f5 ################################################################## # are we running in a terminal? @@ -99,12 +99,16 @@ getConfigKey() { [[ "$1" =~ ^[-${azAZo9},._]+$ ]] || return 3 [ -r "${BOTCONFIG}.jssh" ] && sed -n 's/\["'"$1"'"\]\t*"\(.*\)"/\1/p' "${BOTCONFIG}.jssh" | tail -n 1 } -# escape / remove text characters for json strings, eg. " -> \" -# $1 string -# output escaped string +# escape characters in json strings for telegram +# $1 string, output escaped string JsonEscape(){ 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 # return true if token seems to be valid check_token(){ @@ -461,7 +465,7 @@ sendJson(){ if [ -n "${BASHBOTDEBUG}" ] ; then log_update "sendJson (${DETECTED_CURL}) CHAT=${chat#*:} JSON=${2:0:100} URL=${3##*/}" # 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 # chat id not a number if [[ "${chat}" == *"NAN\"," ]]; then