[v2,16/18] initscripts fkt: keep readhash compatible with older implementation

Message ID 20240616160245.18865-17-jonatan.schlag@ipfire.org
State New
Headers
Series [v2,01/18] tests: Add bash lib |

Commit Message

Jonatan Schlag June 16, 2024, 4:02 p.m. UTC
  With the use of eval BLUE_DEV='blue0 net0' stored "blue0 net0" in the
variable BLUE_DEV not "'blue0 net0'"

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
 src/initscripts/system/functions               | 4 ++++
 tests/src/initscripts/system/functions/test.sh | 1 +
 2 files changed, 5 insertions(+)
  

Patch

diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions
index c9c4c0675..6d72e4119 100644
--- a/src/initscripts/system/functions
+++ b/src/initscripts/system/functions
@@ -932,6 +932,10 @@  readhash() {
 			continue
 		fi
 
+		# strip leading and trailing single quotes
+		val="${val#\'}"
+		val="${val%\'}"
+
 		printf -v "${array}[${key}]" "%s" "${val}"
 	done < "${file}"
 }
diff --git a/tests/src/initscripts/system/functions/test.sh b/tests/src/initscripts/system/functions/test.sh
index a2d6535a5..e7f695f55 100755
--- a/tests/src/initscripts/system/functions/test.sh
+++ b/tests/src/initscripts/system/functions/test.sh
@@ -14,6 +14,7 @@  readhash "CONFIG" "${SCRIPT_PATH}/data/1"
 # test if we read the correct data
 test_value_in_array "CONFIG" "RED_DHCP_HOSTNAME" "ipfire"
 test_value_in_array "CONFIG" "BLUE_MACADDR" "bc:30:7d:58:6b:e3"
+test_value_in_array "CONFIG" "BLUE_DEV" "blue0 net0"
 
 # Test that comments are skipped
 # apparently the way we read the file strips the whitespace, so the key does not contain any whitespace either