[type/__block] Quote prefix and suffix correctly

Before prefix and suffix were not allowed to contain " (quotes).
This commit is contained in:
Takashi Yoshi 2019-04-24 11:02:32 +02:00
parent aba1ae68f0
commit 510ea220f2
1 changed files with 6 additions and 1 deletions

View File

@ -18,6 +18,11 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>. # along with cdist. If not, see <http://www.gnu.org/licenses/>.
# #
# quote function from http://www.etalabs.net/sh_tricks.html
quote() {
printf '%s\n' "$1" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/'/"
}
file="$(cat "$__object/parameter/file" 2>/dev/null || echo "/$__object_id")" file="$(cat "$__object/parameter/file" 2>/dev/null || echo "/$__object_id")"
state_should=$(cat "$__object/parameter/state") state_should=$(cat "$__object/parameter/state")
prefix=$(cat "$__object/parameter/prefix" 2>/dev/null || echo "#cdist:__block/$__object_id") prefix=$(cat "$__object/parameter/prefix" 2>/dev/null || echo "#cdist:__block/$__object_id")
@ -46,7 +51,7 @@ tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX)
if [ -f "$file" ]; then if [ -f "$file" ]; then
cp -p "$file" "\$tmpfile" cp -p "$file" "\$tmpfile"
fi fi
awk -v prefix="^$prefix\$" -v suffix="^$suffix\$" ' awk -v prefix=^$(quote "$prefix")\$ -v suffix=^$(quote "$suffix")\$ '
{ {
if (match(\$0,prefix)) { if (match(\$0,prefix)) {
triggered=1 triggered=1