From 1f3e672018971fb60d7c41c568fd653df6d317b1 Mon Sep 17 00:00:00 2001 From: Brennan Kinney <5098581+polarathene@users.noreply.github.com> Date: Mon, 6 Jun 2022 11:02:52 +1200 Subject: [PATCH] fix(listmailuser): Don't parse comments when reading config (#2617) * fix(listmailuser): Don't parse comments Avoids passing comments to `dovecot_quota_to_hr()` which fails to handle it and would throws errors. * chore: Move config filter method to `helpers/utils.sh` --- target/bin/listmailuser | 3 ++- target/scripts/helpers/utils.sh | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/target/bin/listmailuser b/target/bin/listmailuser index 83343c3a..95dbc070 100755 --- a/target/bin/listmailuser +++ b/target/bin/listmailuser @@ -47,6 +47,7 @@ do else echo fi -done < "${DATABASE}" +done < <(_filter_to_valid_lines "${DATABASE}") + exit 0 diff --git a/target/scripts/helpers/utils.sh b/target/scripts/helpers/utils.sh index f217b8d8..13d39d12 100644 --- a/target/scripts/helpers/utils.sh +++ b/target/scripts/helpers/utils.sh @@ -5,8 +5,16 @@ function _escape echo "${1//./\\.}" } -# Check if string input is an empty line, only whitespaces -# or `#` as the first non-whitespace character. +# Returns input after filtering out lines that are: +# empty, white-space, comments (`#` as the first non-whitespace character) +function _filter_to_valid_lines +{ + grep --extended-regexp --invert-match "^\s*$|^\s*#" "${1}" || true +} + +# TODO: Only used by `relay.sh`, will be removed in future. +# Similar to _filter_to_valid_lines, but only returns a status code +# to indicate invalid line(s): function _is_comment { grep -q -E "^\s*$|^\s*#" <<< "${1}"