Skip to content

Commit 8239181

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

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

pkg/docker/entrypoint.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,29 @@ 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+
var="'${var}'"
81+
fi
82+
83+
echo "${var}"
84+
}
85+
7086
# Check whether the external configuration database exists if it is being used.
7187
external_config_db_exists="False"
7288
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)")
89+
# Support both quoted and unquoted URIs for backwards compatibility
90+
PGADMIN_CONFIG_CONFIG_DATABASE_URI=$(ensure_quoted "${PGADMIN_CONFIG_CONFIG_DATABASE_URI}")
91+
92+
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)")
7493
fi
7594

7695
# DRY of the code to load the PGADMIN_SERVER_JSON_FILE

0 commit comments

Comments
 (0)