From 0d4868dcd52c5c172c680bcf5aa42b3da16c7611 Mon Sep 17 00:00:00 2001 From: Matthias Stecher Date: Sat, 20 Mar 2021 15:39:38 +0100 Subject: [PATCH] __ini_value: new parameter --quote This parameter ensures the value is surrounded by double quotes. As it directly edits the value variable, the quoting will be added/removed automaticly. --- cdist/conf/type/__ini_value/explorer/state | 5 +++++ cdist/conf/type/__ini_value/files/common.awk | 7 ++++++- cdist/conf/type/__ini_value/man.rst | 4 ++++ cdist/conf/type/__ini_value/parameter/boolean | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__ini_value/explorer/state b/cdist/conf/type/__ini_value/explorer/state index 3827a354..507cabe9 100755 --- a/cdist/conf/type/__ini_value/explorer/state +++ b/cdist/conf/type/__ini_value/explorer/state @@ -57,6 +57,11 @@ BEGIN { comment_signs[i++] = tmp } + if(system("test -f " (_param "quote")) == 0) { + # quote it now that it only wins checks against quoted values + value = ("\"" value "\"") + } + found=0 curr_section="" if(section == "") diff --git a/cdist/conf/type/__ini_value/files/common.awk b/cdist/conf/type/__ini_value/files/common.awk index c8505b40..e5f3594c 100644 --- a/cdist/conf/type/__ini_value/files/common.awk +++ b/cdist/conf/type/__ini_value/files/common.awk @@ -11,6 +11,11 @@ BEGIN { get_param_array("comment-sign", comment_signs) comment_sign = comment_signs[0] + if(system("test -f " (_param "quote")) == 0) { + # quote it now that it only wins checks against quoted values + value = ("\"" value "\"") + } + base_spaces = spaces(indentation) delimiter_spaces = spaces(delimiter_space) delimiter_w_spaces = (delimiter_spaces delimiter delimiter_spaces) @@ -59,5 +64,5 @@ function v_print_commented() { } # print comment function c_print() { - printf "%s%s%s%s%s", base_spaces, comment_sign, " ", comment, ORS + printf "%s%s %s%s", base_spaces, comment_sign, comment, ORS } diff --git a/cdist/conf/type/__ini_value/man.rst b/cdist/conf/type/__ini_value/man.rst index 0812d432..38a8d67c 100644 --- a/cdist/conf/type/__ini_value/man.rst +++ b/cdist/conf/type/__ini_value/man.rst @@ -79,6 +79,10 @@ normalize configuration file. Even if a key-value pair is correct as-is, it will correct the line to be pretty and perfect. +quote + Wrap double quotes (``"``) around the value. If the value is previously + unquoted, the file will be modified to quote the value. + MESSAGES -------- diff --git a/cdist/conf/type/__ini_value/parameter/boolean b/cdist/conf/type/__ini_value/parameter/boolean index f9a8b6aa..5b7d2b39 100644 --- a/cdist/conf/type/__ini_value/parameter/boolean +++ b/cdist/conf/type/__ini_value/parameter/boolean @@ -1 +1,2 @@ normalize +quote