[2/3] initscripts: readhash: Only strip quotes if they exist

Message ID 20241206164217.3840140-2-michael.tremer@ipfire.org
State New
Headers
Series [1/3] tests: Fix path to bash |

Commit Message

Michael Tremer Dec. 6, 2024, 4:42 p.m. UTC
  Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
---
 src/initscripts/system/functions | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
  

Patch

diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions
index 125aa1dc6..094e35495 100644
--- a/src/initscripts/system/functions
+++ b/src/initscripts/system/functions
@@ -899,7 +899,6 @@  readhash() {
 
 	local line
 	while read -r line; do
-
 		# Skip Blank Lines
 		if [[ ${line} =~ ^[[:space:]]*$ ]]; then
 			continue
@@ -932,8 +931,12 @@  readhash() {
 		fi
 
 		# strip leading and trailing single quotes
-		val="${val#\'}"
-		val="${val%\'}"
+		case "${val}" in
+			'*')
+				val="${val#\'}"
+				val="${val%\'}"
+				;;
+		esac
 
 		printf -v "${array}[${key}]" "%s" "${val}"
 	done < "${file}"