Skip to content

Commit ae4e011

Browse files
committed
fixed variable quoting
for backwards compatibility, quotes are only added if the variable doesn't already contain single or double quotes
1 parent cc0377f commit ae4e011

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

pkg/docker/entrypoint.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,30 @@ EOF
6767
done
6868
fi
6969

70+
# Ensures the variable starts and ends in quotes after trimming
71+
ensure_quoted() {
72+
local var="$1"
73+
74+
# Trim whitespaces
75+
var="${var#"${var%%[![:space:]]*}"}"
76+
var="${var%"${var##*[![:space:]]}"}"
77+
78+
# Check if the variable is already double or single quoted
79+
if [[ ! $var =~ ^\"(.*)\"$ && ! $var =~ ^\'(.*)\'$ ]]; then
80+
# Use docstrings in case the value contains quote characters inside
81+
var="'''${var}'''"
82+
fi
83+
84+
echo "${var}"
85+
}
86+
7087
# Check whether the external configuration database exists if it is being used.
7188
external_config_db_exists="False"
7289
if [ -n "${PGADMIN_CONFIG_CONFIG_DATABASE_URI}" ]; then
73-
external_config_db_exists=$(cd /pgadmin4/pgadmin/utils && /venv/bin/python3 -c "from check_external_config_db import check_external_config_db; val = check_external_config_db("${PGADMIN_CONFIG_CONFIG_DATABASE_URI}"); print(val)")
90+
# Support both quoted and unquoted URIs for backwards compatibility
91+
PGADMIN_CONFIG_CONFIG_DATABASE_URI=$(ensure_quoted "${PGADMIN_CONFIG_CONFIG_DATABASE_URI}")
92+
93+
external_config_db_exists=$(cd /pgadmin4/pgadmin/utils && /venv/bin/python3 -c "from check_external_config_db import check_external_config_db; val = check_external_config_db(${PGADMIN_CONFIG_CONFIG_DATABASE_URI}); print(val)")
7494
fi
7595

7696
# DRY of the code to load the PGADMIN_SERVER_JSON_FILE

0 commit comments

Comments
 (0)