Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/textfsm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ def testFSMValue(self):
textfsm.TextFSMTemplateError, v.Parse, 'Value Required beer'
)

# A backslash in the value name is rejected at name-check time.
v = textfsm.TextFSMValue(options_class=textfsm.TextFSMOptions)
self.assertRaises(
textfsm.TextFSMTemplateError, v.Parse, r'Value beer\ol1 (\S+)'
)

tplt = 'Value beer\\ol1 (\\S+)\n\nStart\n ^$beer\\ol1x -> Next\n'
Comment thread
harro marked this conversation as resolved.
Resolved
self.assertRaises(
textfsm.TextFSMTemplateError, textfsm.TextFSM, io.StringIO(tplt)
)

# Unbalanced parenthesis can exist if within square "[]" braces.
v = textfsm.TextFSMValue(options_class=textfsm.TextFSMOptions)
v.Parse('Value beer (boo[(]hoo)')
Expand Down
4 changes: 2 additions & 2 deletions textfsm/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def Parse(self, value):
self.name = value_line[1]
self.regex = ' '.join(value_line[2:])

if len(self.name) > self.max_name_len:
if len(self.name) > self.max_name_len or '\\' in self.name:
raise TextFSMTemplateError(
"Invalid Value name '%s' or name too long." % self.name
)
Expand All @@ -319,7 +319,7 @@ def Parse(self, value):
except re.error as exc:
raise TextFSMTemplateError(str(exc)) from exc

self.template = re.sub(r'^\(', '(?P<%s>' % self.name, self.regex)
self.template = '(?P<%s>%s' % (self.name, self.regex[1:])

# Compile and store the regex object only on List-type values for use in
# nested matching
Expand Down
Loading