Closed kbrock closed 2 years ago
I really want to avoid an eval, because we will get dinged in security scans for sure. Curious if there is a better way.
Nice! Not necessarily for this PR, but I'm wondering if we can maybe add a proper spec for this? Perhaps with bats? https://github.com/bats-core/bats-core
update:
It runs on the following test file:
#good
SPACE="sp ace"
ESPACE = value
NQUOTE=no quote
QUOTES='quotes'
DQUOTES="dquotes"
COMMENT="value" # comment
COMMENT2=value # comment
COMMENT3="value" # comment
COMMENT4=value # comment
COMMENT5=value_with_#_in_it
PLAIN=plain
EQUAL=NAME=VALUE
# dangerous
DOLLAR="$dollar"
DOLLAR2="${dollar}"
SHELL="$(ls)"
TICKS=`ls`
# fails
COMMENT6="quoted # value"
COMMENT7="slash \# value"
# bad
$x=y
$(ls)
" #"
since it looks like a comment in a quoted string.
Since the old code did not support any comments on the same line, this seemed reasonable.The regular expression matching did slow this down a bit. Still faster than the original 2 seconds.
$ time ./evm
real 0m0.013s
user 0m0.006s
sys 0m0.005s
not sure how to test since the path of the input file is hardcoded in the script.
hmmm ok.
Does this need to go back to najdorf?
Does this need to go back to najdorf?
Yes. It protects us from many more bad configuration file formats
Backported to najdorf
in commit b604e80b91832cac3049fd0c8c52b2e16e315f23.
commit b604e80b91832cac3049fd0c8c52b2e16e315f23
Author: Jason Frey <fryguy9@gmail.com>
Date: Fri Feb 25 17:37:23 2022 -0500
Merge pull request #345 from kbrock/env_vars_3
fix quoted strings in properties files
(cherry picked from commit 05cc4498b5d54a891114bd1af121d816c94a1d61)
Issue
We want the ability to have quoted strings in our
/etc/defalt/manageiq.properties
files. UnfortunatelyThis was introduced in #329
Solution
eval
properly sets the property value, andexport
exposes the variable outside the shell to other processestest run
Other changes
As seen for example
c
above, trailing comments on a line of a file are now ignored.Fixes #335