summaryrefslogtreecommitdiff
path: root/python/vyos/configtree.py
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2019-03-17 21:36:55 +0100
committerDaniil Baturin <daniil@baturin.org>2019-03-17 21:38:01 +0100
commit0a10a3bd9d346b1abdf88301d6904a5346ffe6d0 (patch)
treee5221a6dee5a0e1afe55a7a2cf7e1d0985a3cb59 /python/vyos/configtree.py
parentedfe3f1f42b419a3c96e53bbcbc3d5a4af34e0b9 (diff)
downloadvyos-1x-0a10a3bd9d346b1abdf88301d6904a5346ffe6d0.tar.gz
vyos-1x-0a10a3bd9d346b1abdf88301d6904a5346ffe6d0.zip
[vyos.configtree] T1305: allow configs to end with leaf nodes.
Diffstat (limited to 'python/vyos/configtree.py')
-rw-r--r--python/vyos/configtree.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/python/vyos/configtree.py b/python/vyos/configtree.py
index 1f71ddd7c..a812b62ec 100644
--- a/python/vyos/configtree.py
+++ b/python/vyos/configtree.py
@@ -41,6 +41,12 @@ def strip_comments(s):
else:
config_end = 0
break
+ elif (state == INITIAL) and not re.match(r'(\s|\/)', c):
+ # Assume there are no (more) trailing comments,
+ # this is an end of a node: either a brace of the last character
+ # of a leaf node value
+ config_end = i + 1
+ break
elif (state == INITIAL) and (c == '/'):
# A comment begins, or it's a stray slash
if (s[i-1] == '*'):
@@ -48,10 +54,6 @@ def strip_comments(s):
i -= 2
else:
raise ValueError("Invalid syntax: stray slash at character {0}".format(i + 1))
- elif (state == INITIAL) and (c == '}'):
- # We are not inside a comment, that's the end of the last node
- config_end = i + 1
- break
elif (state == IN_COMMENT) and (c == '*'):
# A comment ends here
try:
@@ -64,6 +66,7 @@ def strip_comments(s):
# Ignore everything inside comments, including braces
i -= 1
else:
+ # Shouldn't happen
raise ValueError("Invalid syntax at character {0}: invalid character {1}".format(i + 1, c))
return (s[0:config_end], s[config_end+1:])