summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-06-16 10:57:52 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-06-16 10:57:52 -0700
commit03745206b8e26bb7a3e7119abcd8a03d95dbc897 (patch)
treeb83f5c8249fe84bff008b2dfc085ba891745582d /cloudinit/util.py
parent60f176e13836d77616ae07774fda2139fde790fc (diff)
downloadvyos-cloud-init-03745206b8e26bb7a3e7119abcd8a03d95dbc897.tar.gz
vyos-cloud-init-03745206b8e26bb7a3e7119abcd8a03d95dbc897.zip
Add a restricted set of characters which can be used in filenames when cleaning them.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index ed12dada..6e8ce96e 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -64,6 +64,7 @@ LOG = logging.getLogger(__name__)
FN_REPLACEMENTS = {
os.sep: '_',
}
+FN_ALLOWED = ('_-.()' + string.digits + string.ascii_letters)
# Helper utils to see if running in a container
CONTAINER_TESTS = ['running-in-container', 'lxc-is-container']
@@ -227,7 +228,14 @@ def read_conf(fname):
def clean_filename(fn):
for (k, v) in FN_REPLACEMENTS.iteritems():
fn = fn.replace(k, v)
- return fn.strip()
+ removals = []
+ for k in fn:
+ if k not in FN_ALLOWED:
+ removals.append(k)
+ for k in removals:
+ fn = fn.replace(k, '')
+ fn = fn.strip()
+ return fn
def decomp_str(data):