diff options
author | John Estabrook <jestabro@sentrium.io> | 2019-11-26 11:51:54 -0600 |
---|---|---|
committer | John Estabrook <jestabro@sentrium.io> | 2019-12-03 11:17:48 -0600 |
commit | 145b937d3d8e3734d987b5486fe861f660c6e79b (patch) | |
tree | da670c6d31d9cef41de2fb21d460e5818cbfd574 /python/vyos/configtree.py | |
parent | 41212805fa9db0db590b8207372a3d2ec7382fef (diff) | |
download | vyos-1x-145b937d3d8e3734d987b5486fe861f660c6e79b.tar.gz vyos-1x-145b937d3d8e3734d987b5486fe861f660c6e79b.zip |
T1801: move escaping of backslashes into configtree
Diffstat (limited to 'python/vyos/configtree.py')
-rw-r--r-- | python/vyos/configtree.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/python/vyos/configtree.py b/python/vyos/configtree.py index 77cffe90b..0274f3573 100644 --- a/python/vyos/configtree.py +++ b/python/vyos/configtree.py @@ -18,6 +18,12 @@ import json from ctypes import cdll, c_char_p, c_void_p, c_int +def escape_backslash(string: str) -> str: + """Escape single backslashes in string that are not in escape sequence""" + p = re.compile(r'(?<!\\)[\\](?!b|f|n|r|t|\\[^bfnrt])') + result = p.sub(r'\\\\', string) + return result + def strip_comments(s): """ Split a config string into the config section and the trailing comments """ INITIAL = 0 @@ -169,6 +175,7 @@ class ConfigTree(object): self.__destroy.argtypes = [c_void_p] config_section, comments_section = strip_comments(config_string) + config_section = escape_backslash(config_section) config = self.__from_string(config_section.encode()) if config is None: msg = self.__get_error().decode() |