From patchwork Sun Jun 16 16:02:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7874 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hql71ZPz3x1l for ; Sun, 16 Jun 2024 16:03:31 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2Hqj1xYcz5mZ; Sun, 16 Jun 2024 16:03:29 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2Hqj1Sjnz33Fy; Sun, 16 Jun 2024 16:03:29 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqd5cBvz33Fq for ; Sun, 16 Jun 2024 16:03:25 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2Hqc6yHYz4XG; Sun, 16 Jun 2024 16:03:24 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553805; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LxemwrvfhcWJzhSOl4YSPOPEH0qR9p5fRQjXq3aVVas=; b=zfEXGjrNn+zrncrCIecieqPctwUtuMc7EY/pfYh9G7riOo8XUloR1eljUlQeqEtiDJ1gdM +bhuwhf9VOqPiqCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553805; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LxemwrvfhcWJzhSOl4YSPOPEH0qR9p5fRQjXq3aVVas=; b=JZKt9GQjUruUNmuimIUf5h1GTngRyNxirXZDd/4DLWlN7B+EoDIaPGIaDXJolJS29FVioo xRw+Z4fY+T5OrXyGVJOHOTK+QNX6YwG2xKD6BwdfSkINSA/d1xKZvPxLf4KIjHl0SrE7w3 NhWwKBv/mKfGM/nNlm3PIXsqwswPXpdwPahWrqFZYuL+CrSAYLrjfQ0Ly88l6rMQO53FZm cAvPy8gWEex5XWe3of5LoZFgbu7Im3UDo5dpt2rbfB3r+OVnmOnKPoKavGxTQ/HkNmY2tT quWHe4pV20VneGFh5iNKQJPj7z7QK62Byf609On3P/oG3pAA1rZYtyDY/KWHYA== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 12/18] initscripts fkt: Ignore comments in readhash Date: Sun, 16 Jun 2024 18:02:39 +0200 Message-Id: <20240616160245.18865-13-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: PQNZWVOWM2XGNME5FEAAZPDL334UPZBT X-Message-ID-Hash: PQNZWVOWM2XGNME5FEAAZPDL334UPZBT X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- src/initscripts/system/functions | 5 +++++ tests/src/initscripts/system/functions/data/1 | 3 +++ tests/src/initscripts/system/functions/test.sh | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions index 3f01be9e0..6107463fc 100644 --- a/src/initscripts/system/functions +++ b/src/initscripts/system/functions @@ -906,6 +906,11 @@ readhash() { continue fi + # Skip Comments + if [[ ${line} =~ ^#.*$ ]]; then + continue + fi + local key="${line%=*}" local val="${line#*=}" diff --git a/tests/src/initscripts/system/functions/data/1 b/tests/src/initscripts/system/functions/data/1 index 8aca9422b..c75620b6b 100644 --- a/tests/src/initscripts/system/functions/data/1 +++ b/tests/src/initscripts/system/functions/data/1 @@ -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 diff --git a/tests/src/initscripts/system/functions/test.sh b/tests/src/initscripts/system/functions/test.sh index 751be6884..915f098a0 100755 --- a/tests/src/initscripts/system/functions/test.sh +++ b/tests/src/initscripts/system/functions/test.sh @@ -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"