Skip to content

Commit

Permalink
settings: clarify that null defaults are supported, using the syntax …
Browse files Browse the repository at this point in the history
…"${VAR_NAME}"

Using "${VAR_NAME:null}", instead, would define the literal string "null".
  • Loading branch information
muxator committed Apr 21, 2020
1 parent 68ff6d4 commit 9882362
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions settings.json.docker
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
3 changes: 3 additions & 0 deletions settings.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
10 changes: 9 additions & 1 deletion src/node/utils/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9882362

Please sign in to comment.