diff options
author | Patrick Spek <p.spek@tyil.nl> | 2024-02-28 08:32:34 +0100 |
---|---|---|
committer | Patrick Spek <p.spek@tyil.nl> | 2024-04-02 09:25:04 +0200 |
commit | ca33873ad616bdb4d38cd9e15aa184d1ab2aba05 (patch) | |
tree | 164a232bd917c48efeb150f61ff5d713878bf82d | |
parent | 7c970a5c40b1b273242700b7298bd128869b5756 (diff) |
Fix empty default values
-rw-r--r-- | CHANGELOG.md | 10 | ||||
-rw-r--r-- | lib/util/config.bash | 10 |
2 files changed, 16 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index b443386..407e62d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ <!-- -SPDX-FileCopyrightText: 2023 Patrick Spek <p.spek@tyil.nl> +SPDX-FileCopyrightText: 2024 Patrick Spek <p.spek@tyil.nl> SPDX-License-Identifier: AGPL-3.0-or-later --> @@ -11,6 +11,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [UNRELEASED] + +### Fixed + +- Passing an empty string as default value to `config` should now properly + return an empty string without a warning about the configuration key not + existing. + ## [2.0.2] - 2024-02-28 ### Fixed diff --git a/lib/util/config.bash b/lib/util/config.bash index 76b6567..9817cf3 100644 --- a/lib/util/config.bash +++ b/lib/util/config.bash @@ -17,7 +17,11 @@ config_subkeys() { config_for() { local host=$1 ; shift local key=$1 ; shift - local default=$1 ; shift + + # Use a variable definition test to define default, in order to ensure + # it is _not_ defined if no argument for it was passed, but _is_ + # defined even if an empty string was passed. + test -v 1 && { local default=$1 ; shift ; } local default local file @@ -67,8 +71,8 @@ config_for() { fi done - # Return default value - if [[ -n $default ]] + # Return default value, if one has been defined + if test -v default then printf "%s" "$default" return |