From ce95a02b1aa618dda4b24c62b19107995cd08a69 Mon Sep 17 00:00:00 2001
From: Patrick Spek
Date: Wed, 28 Feb 2024 08:32:34 +0100
Subject: Fix empty default values
---
CHANGELOG.md | 10 +++++++++-
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 @@
@@ -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
--
cgit v1.1