From 1d2df8d4998a7cf06ed2a2b67e7434c7d414b029 Mon Sep 17 00:00:00 2001 From: Brennan Kinney <5098581+polarathene@users.noreply.github.com> Date: Tue, 23 May 2023 11:02:30 +1200 Subject: [PATCH] fix: DB helper should properly filter entries (#3359) Previously it was assumed the sed operation was applying the sed expressions as a sequence, but it did not seem to filter entries being looked up correctly. Instead any line that matched either sed expression pattern was output (_value without matching key, values split by the delimiter_), then grep would match any of that causing false-positives. Resolved by piping the first sed expression into the next. --- target/scripts/helpers/database/db.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/target/scripts/helpers/database/db.sh b/target/scripts/helpers/database/db.sh index 66476772..3299fa21 100644 --- a/target/scripts/helpers/database/db.sh +++ b/target/scripts/helpers/database/db.sh @@ -132,11 +132,11 @@ function __db_list_already_contains_value { # Avoids accidentally matching a substring (case-insensitive acceptable): # 1. Extract the current value of the entry (`\1`), - # 2. If a value list, split into separate lines (`\n`+`g`) at V_DELIMITER, + # 2. Value list support: Split values into separate lines (`\n`+`g`) at V_DELIMITER, # 3. Check each line for an exact match of the target VALUE - sed -e "s/^${KEY_LOOKUP}\(.*\)/\1/" \ - -e "s/${V_DELIMITER}/\n/g" \ - "${DATABASE}" | grep -qi "^${_VALUE_}$" + sed -ne "s/^${KEY_LOOKUP}\+\(.*\)/\1/p" "${DATABASE}" \ + | sed -e "s/${V_DELIMITER}/\n/g" \ + | grep -qi "^${_VALUE_}$" }