Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(scripts): report a quoted .env value with a quoted comment
Yudhi Armyndharis50bab04f7dd4
diff --git a/scripts/lib-env.sh b/scripts/lib-env.shindex 533fee5c4..88fea09ca 100644--- a/scripts/lib-env.sh+++ b/scripts/lib-env.sh@@ -43,8 +43,14 @@ openwa_env_file_value() {case "$value" in\"*\\*) ;; # dotenv expands \n and \r inside double quotes\"*\" | \'*\' | \`*\`)- printf '%s' "${value:1:${#value}-2}"- return 0+ # A quote inside means the pair does not wrap the whole value: a comment ending in one follows it.+ case "${value:1:${#value}-2}" in+ *"${value:0:1}"*) ;;+ *)+ printf '%s' "${value:1:${#value}-2}"+ return 0+ ;;+ esac;;\"* | \'* | \`*) ;; # the quote does not close the value, as with a trailing comment*)diff --git a/scripts/smoke-test-backup-restore.sh b/scripts/smoke-test-backup-restore.shindex bec191802..d759bfd7b 100755--- a/scripts/smoke-test-backup-restore.sh+++ b/scripts/smoke-test-backup-restore.sh@@ -1417,6 +1417,8 @@ DATABASE_NAME=""MAIN_DATABASE_NAME='./data/quoted main.sqlite'BAILEYS_AUTH_DIR=./data/bl#inlineSESSION_DATA_PATH="./data/sess" # quoted, then a comment+STORAGE_LOCAL_PATH="./data/media" # see "docs"+PLUGIN_STATE_DIR='./data/state' # it'ENVprintf 'DATABASE_NAME=./elsewhere/openwa.sqlite\nSESSION_DATA_PATH=./elsewhere/sess\n' >"$AG/data/.env.generated"resolve_ag() {@@ -1424,15 +1426,17 @@ resolve_ag() {}# A blank value and an unparsed line both resolve to the default, never to data/.env.generated.for check in 'PLUGINS_DIR|./data/plugins' 'DATABASE_NAME|DEFAULT' 'MAIN_DATABASE_NAME|./data/quoted main.sqlite' \- 'BAILEYS_AUTH_DIR|./data/bl' 'SESSION_DATA_PATH|DEFAULT'; do+ 'BAILEYS_AUTH_DIR|./data/bl' 'SESSION_DATA_PATH|DEFAULT' 'STORAGE_LOCAL_PATH|DEFAULT' 'PLUGIN_STATE_DIR|DEFAULT'; dokey="${check%%|*}"got="$(resolve_ag "$key" DEFAULT)"if [ "$got" != "${check#*|}" ]; thenfail "(ag) $key resolved to '$got', expected '${check#*|}'"fidone-if [ "$(grep -c 'do not parse' "$AG/err")" -ne 1 ] || ! grep -q 'sets SESSION_DATA_PATH in a form' "$AG/err"; then- fail "(ag) the parse warning did not name exactly the one unparsed line: $(cat "$AG/err")"+# A comment ending in the value's own quote must not pass for the closing quote.+if [ "$(grep -c 'do not parse' "$AG/err")" -ne 3 ] || ! grep -q 'sets SESSION_DATA_PATH in a form' "$AG/err" ||+ ! grep -q 'sets STORAGE_LOCAL_PATH in a form' "$AG/err" || ! grep -q 'sets PLUGIN_STATE_DIR in a form' "$AG/err"; then+ fail "(ag) the parse warning did not name exactly the three unparsed lines: $(cat "$AG/err")"fipass "(ag) dotenv's quoted, commented and empty forms resolve like the app, and an unparsed line stops the lookup"