summaryrefslogtreecommitdiff
path: root/cloudinit/distros/parsers/sys_conf.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-10-11 18:48:50 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-10-11 18:48:50 -0700
commit66f6d2d4fd1e8c1b397c9533ee0596d7b09e9824 (patch)
treec0deb0a9c6c973d1ca24b0835b037f399b992195 /cloudinit/distros/parsers/sys_conf.py
parent059a4c45ab2b4439872d138452d6296bfe82be07 (diff)
downloadvyos-cloud-init-66f6d2d4fd1e8c1b397c9533ee0596d7b09e9824.tar.gz
vyos-cloud-init-66f6d2d4fd1e8c1b397c9533ee0596d7b09e9824.zip
Update to use pipes.quote to ensure that
variables adjusted in sysconfig files are properly quoted for there common use case, that being sourced into shell scripts.
Diffstat (limited to 'cloudinit/distros/parsers/sys_conf.py')
-rw-r--r--cloudinit/distros/parsers/sys_conf.py24
1 files changed, 10 insertions, 14 deletions
diff --git a/cloudinit/distros/parsers/sys_conf.py b/cloudinit/distros/parsers/sys_conf.py
index 3d8802b8..7549c7a3 100644
--- a/cloudinit/distros/parsers/sys_conf.py
+++ b/cloudinit/distros/parsers/sys_conf.py
@@ -18,6 +18,7 @@
from StringIO import StringIO
+import pipes
import re
# This library is used to parse/write
@@ -30,6 +31,7 @@ import re
import configobj
+
class SysConf(configobj.ConfigObj):
def __init__(self, contents):
configobj.ConfigObj.__init__(self, contents,
@@ -50,24 +52,18 @@ class SysConf(configobj.ConfigObj):
raise ValueError('Value "%s" is not a string' % (value))
if len(value) == 0:
return ''
- if re.search(r"[\n\r]", value):
- raise ValueError('Value "%s" cannot be safely quoted.' % (value))
- quot = "%s"
- if '#' in value:
- quot = self._get_single_quote(value)
- elif value[0] in ['"', "'"] and value[-1] in ['"', "'"]:
- # Already quoted, leave it be
- pass
- elif "'" in value and '"' in value:
- quot = self._get_triple_quote(value)
+ quot_func = (lambda x: str(x))
+ if value[0] in ['"', "'"] and value[-1] in ['"', "'"]:
+ if len(value) == 1:
+ quot_func = self._get_single_quote
else:
- # Quote whitespace if it isn't the start+end of a shell command
+ # Quote whitespace if it isn't the start + end of a shell command
white_space_ok = False
if value.strip().startswith("$(") and value.strip().endswith(")"):
white_space_ok = True
- if re.search(r"[\t ]", value) and not white_space_ok:
- quot = self._get_single_quote(value)
- return quot % (value)
+ if re.search(r"[\t\r\n ]", value) and not white_space_ok:
+ quot_func = pipes.quote
+ return quot_func(value)
def _write_line(self, indent_string, entry, this_entry, comment):
# Ensure it is formatted fine for