diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-10-11 19:10:42 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-10-11 19:10:42 -0700 |
commit | 3cf8b618f9efcdb2e9cca695c2930a2bf14d42ec (patch) | |
tree | 2c1449b8989f1015a222209afb9ec582350ab2a0 /cloudinit/distros | |
parent | 66f6d2d4fd1e8c1b397c9533ee0596d7b09e9824 (diff) | |
download | vyos-cloud-init-3cf8b618f9efcdb2e9cca695c2930a2bf14d42ec.tar.gz vyos-cloud-init-3cf8b618f9efcdb2e9cca695c2930a2bf14d42ec.zip |
Handle the case where the value contains shell
variables to be expanded which when using
pipes.quote will now not be expanded, so add
some checks to ensure that this case will still happen.
Diffstat (limited to 'cloudinit/distros')
-rw-r--r-- | cloudinit/distros/parsers/sys_conf.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/cloudinit/distros/parsers/sys_conf.py b/cloudinit/distros/parsers/sys_conf.py index 7549c7a3..80c305fe 100644 --- a/cloudinit/distros/parsers/sys_conf.py +++ b/cloudinit/distros/parsers/sys_conf.py @@ -31,6 +31,12 @@ import re import configobj +def _contains_shell_variable(text): + if (re.search(r"\$\{.+\}", text) or + re.search(r"\$[a-zA-Z_]+[a-zA-Z0-9_]*", text)): + return True + return False + class SysConf(configobj.ConfigObj): def __init__(self, contents): @@ -62,7 +68,16 @@ class SysConf(configobj.ConfigObj): if value.strip().startswith("$(") and value.strip().endswith(")"): white_space_ok = True if re.search(r"[\t\r\n ]", value) and not white_space_ok: - quot_func = pipes.quote + if _contains_shell_variable(value): + # If it contains shell variables then we likely want to + # leave it alone since the pipes.quote function likes to + # use single quotes which won't get expanded... + if re.search(r"[\n\"']", value): + quot_func = (lambda x: self._get_triple_quote(x) % x) + else: + quot_func = (lambda x: self._get_single_quote(x) % x) + else: + quot_func = pipes.quote return quot_func(value) def _write_line(self, indent_string, entry, this_entry, comment): |