[20/21] initscripts fkt: keep readhash compatible with older implementation

Message ID 20240520090611.10406-21-jonatan.schlag@ipfire.org
State New
Headers
Series [01/21] test: Add bash lib for colors |

Commit Message

Jonatan Schlag May 20, 2024, 9:06 a.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 9981cc732..1a715d7d9 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_that_key_in_arry_has_value "CONFIG" "RED_DHCP_HOSTNAME" "ipfire"
 test_that_key_in_arry_has_value "CONFIG" "BLUE_MACADDR" "bc:30:7d:58:6b:e3"
+test_that_key_in_arry_has_value "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