aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2024-02-28 08:32:34 +0100
committerPatrick Spek <p.spek@tyil.nl>2024-02-28 08:32:34 +0100
commitce95a02b1aa618dda4b24c62b19107995cd08a69 (patch)
treea02b92085f02bdd9a7de568098f70ac358f35d86
parent59c29f83e7795ff764a795aa2c5e41edcbc1f2f0 (diff)
Fix empty default values
-rw-r--r--CHANGELOG.md10
-rw-r--r--lib/util/config.bash10
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