From 9882362e2e7c0363e437945d2062443cfe4e2329 Mon Sep 17 00:00:00 2001 From: muxator Date: Tue, 21 Apr 2020 03:40:49 +0200 Subject: [PATCH] settings: clarify that null defaults are supported, using the syntax "${VAR_NAME}" Using "${VAR_NAME:null}", instead, would define the literal string "null". --- settings.json.docker | 3 +++ settings.json.template | 3 +++ src/node/utils/Settings.js | 10 +++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/settings.json.docker b/settings.json.docker index 0d0891778..99b83bff5 100644 --- a/settings.json.docker +++ b/settings.json.docker @@ -65,6 +65,9 @@ * "password": "${PASSW}" // if PASSW is not defined would result in password === null * "password": "${PASSW:}" // if PASSW is not defined would result in password === '' * + * If you want to use an empty value (null) as default value for a variable, + * simply do not set it, without putting any colons: "${ABIWORD}". + * * 3) if you want to use newlines in the default value of a string parameter, * use "\n" as usual. * diff --git a/settings.json.template b/settings.json.template index 929282898..f01dc7802 100644 --- a/settings.json.template +++ b/settings.json.template @@ -56,6 +56,9 @@ * "password": "${PASSW}" // if PASSW is not defined would result in password === null * "password": "${PASSW:}" // if PASSW is not defined would result in password === '' * + * If you want to use an empty value (null) as default value for a variable, + * simply do not set it, without putting any colons: "${ABIWORD}". + * * 3) if you want to use newlines in the default value of a string parameter, * use "\n" as usual. * diff --git a/src/node/utils/Settings.js b/src/node/utils/Settings.js index 8e478f0da..369a4485f 100644 --- a/src/node/utils/Settings.js +++ b/src/node/utils/Settings.js @@ -421,6 +421,14 @@ function storeSettings(settingsObj) { /* * If stringValue is a numeric string, or its value is "true" or "false", coerce * them to appropriate JS types. Otherwise return stringValue as-is. + * + * Please note that this function is used for converting types for default + * values in the settings file (for example: "${PORT:9001}"), and that there is + * no coercition for "null" values. + * + * If the user wants a variable to be null by default, he'll have to use the + * short syntax "${ABIWORD}", and not "${ABIWORD:null}": the latter would result + * in the literal string "null", instead. */ function coerceValue(stringValue) { // cooked from https://stackoverflow.com/questions/175739/built-in-way-in-javascript-to-check-if-a-string-is-a-valid-number @@ -525,7 +533,7 @@ function lookupEnvironmentVariables(obj) { const defaultValue = match[3]; if ((envVarValue === undefined) && (defaultValue === undefined)) { - console.warn(`Environment variable "${envVarName}" does not contain any value for configuration key "${key}", and no default was given. Returning null. Please check your configuration and environment settings.`); + console.warn(`Environment variable "${envVarName}" does not contain any value for configuration key "${key}", and no default was given. Returning null.`); /* * We have to return null, because if we just returned undefined, the