From 3675d3806f772bf864446dc091b1bbbe6ebf233a Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Thu, 4 Jan 2024 11:39:09 +0100 Subject: Fix values with = being used for templating --- CHANGELOG.md | 7 +++++++ lib/util.bash | 8 ++++---- lib/util/config.bash | 7 ++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0512a1d..32df072 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,13 @@ 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 + +- Configuration values with `=` in their value part should now work properly + with `file_template`. Keys with `=` in them are still *not supported*. + ## [2.0.1] - 2023-09-25 ### Added diff --git a/lib/util.bash b/lib/util.bash index 7bc8a6d..ad84247 100644 --- a/lib/util.bash +++ b/lib/util.bash @@ -162,18 +162,18 @@ file_template() do debug "bashtard/template" "Adding $kv to sedfile at $sedfile" - key="$(awk -F= '{ print $1 }' <<< "$kv")" + key="$(cut -d'=' -f -1 <<< "$kv")" if [[ -z "$key" ]] then - crit "bashtard/template" "Empty key in '$kv' while rendering $file?" + crit "bashtard/template" "Empty key in '$kv' while rendering $file" fi - value="$(awk -F= '{ print $NF }' <<< "$kv")" + value="$(cut -d'=' -f 2- <<< "$kv")" if [[ -z "$value" ]] then - crit "bashtard/template" "Empty key in '$kv' while rendering $file?" + crit "bashtard/template" "Empty key in '$kv' while rendering $file" fi # shellcheck disable=SC2016 diff --git a/lib/util/config.bash b/lib/util/config.bash index 4727706..76b6567 100644 --- a/lib/util/config.bash +++ b/lib/util/config.bash @@ -51,7 +51,12 @@ config_for() { [[ ! -f $file ]] && continue - value="$(awk -F= '$1 == "'"$key"'" { print $NF }' "$file")" + # Use awk to find the right line, then use cut to get the + # actual value. Cutting it out with awk _is_ possible, but + # comes with whitespace issues or having to deal with values + # containing the seperator (=), so using cut is much simpler + # and easier to understand. + value="$(awk -F= '$1 == "'"$key"'" { print $0 }' "$file" | cut -d'=' -f 2-)" if [[ -n $value ]] then -- cgit v1.1