]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
initscripts fkt: Ignore comments in readhash
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Sun, 16 Jun 2024 16:02:39 +0000 (18:02 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 24 Aug 2024 12:19:56 +0000 (12:19 +0000)
As '#Another Comment' is a valid key we test this change by checking if
the comments do not end up as keys in our array.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/initscripts/system/functions
tests/src/initscripts/system/functions/data/1
tests/src/initscripts/system/functions/test.sh

index 507ebb7c5d4d96ef26a5fba4d555d0f8e7e08ec4..d1a1f5b042d28f65b183f7b2eaba8454924392a2 100644 (file)
@@ -905,6 +905,11 @@ readhash() {
                        continue
                fi
 
+               # Skip Comments
+               if [[ ${line} =~ ^#.*$ ]]; then
+                       continue
+               fi
+
                local key="${line%=*}"
                local val="${line#*=}"
 
index 8aca9422bb3d8346c3a69248c3d3cfbd60ead00f..c75620b6b0c7a5491e8d8af27aadb6284357ba63 100644 (file)
@@ -5,6 +5,7 @@ GREEN_DRIVER=r8175
 RED_DEV=red0
 RED_MACADDR=00:c0:08:8a:a0:56
 RED_DRIVER=r8283
+# Another Comment
 BLUE_DEV='blue0 net0'
 BLUE_MACADDR=bc:30:7d:58:6b:e3
 BLUE_DRIVER=rt2800
@@ -15,3 +16,5 @@ RED_NETMASK=0.0.0.0
 RED_TYPE=PPPOE
 RED_NETADDRESS=0.0.0.0
 
+# Comment for testing  
+    # Comment for testing Comments with spaces before
index 751be68844055649080e6d89bd3655b3b4da0621..915f098a0600207c99b4c9e683a1d474bf641195 100755 (executable)
@@ -15,5 +15,11 @@ readhash "CONFIG" "${SCRIPT_PATH}/data/1"
 test_value_in_array "CONFIG" "RED_DHCP_HOSTNAME" "ipfire"
 test_value_in_array "CONFIG" "BLUE_MACADDR" "bc:30:7d:58:6b:e3"
 
+# Test that comments are skipped
+# apparently the way we read the file strips the whitespace, so the key does not contain any whitespace either
+test_that_array_doesnt_have_key "CONFIG" "# Another Comment"
+test_that_array_doesnt_have_key "CONFIG" "# Comment for testing"
+test_that_array_doesnt_have_key "CONFIG" "# Comment for testing Comments with spaces before"
+
 test_that_output_is "${SCRIPT_PATH}/data/1_output_stdout" "1" readhash "CONFIG" "${SCRIPT_PATH}/data/1"
 test_that_output_is "${SCRIPT_PATH}/data/1_output_stderr" "2" readhash "CONFIG" "${SCRIPT_PATH}/data/1"