Environment
- Python version: 3.12.13
- netutils version: 1.19.1
Expected Behavior
An object name containing [ parses like any other.
Observed Behavior
ValueError: Input line is malformed., and the whole config is lost.
_parse_out_offending() replaces a config system replacemsg buffer with a ["<name>"] placeholder, and _build_nested_config() restores it:
if "[" in line:
updated_line = self.uncommon_data.get(line.split('"')[1], None)
if not updated_line:
raise ValueError("Input line is malformed.")
line = updated_line
The guard is "[" in line alone, so any bracketed line is taken for a placeholder and a lookup miss raises. _build_nested_config() receives the first indented line of a top-level block, so only a bracket there triggers it; one deeper in the block is consumed by the method's own loop. A bracketed line with no quotes raises IndexError from line.split('"')[1] before reaching the lookup.
Steps to Reproduce
-
pip install netutils==1.19.1
-
Run:
from netutils.config.parser import FortinetConfigParser
FortinetConfigParser('config firewall address\n edit "obj[1]"\n set subnet 10.0.0.0 255.0.0.0\n next\nend\n')
# ValueError: Input line is malformed.
The same config with edit "obj1" parses.
Possible fix
Take the branch only when the key is one _get_uncommon_lines() produced:
if "[" in line:
parts = line.split('"')
if len(parts) > 2 and parts[1] in self.uncommon_data:
line = self.uncommon_data[parts[1]]
Happy to PR against develop.
Environment
Expected Behavior
An object name containing
[parses like any other.Observed Behavior
ValueError: Input line is malformed., and the whole config is lost._parse_out_offending()replaces aconfig system replacemsgbuffer with a["<name>"]placeholder, and_build_nested_config()restores it:The guard is
"[" in linealone, so any bracketed line is taken for a placeholder and a lookup miss raises._build_nested_config()receives the first indented line of a top-level block, so only a bracket there triggers it; one deeper in the block is consumed by the method's own loop. A bracketed line with no quotes raisesIndexErrorfromline.split('"')[1]before reaching the lookup.Steps to Reproduce
pip install netutils==1.19.1Run:
The same config with
edit "obj1"parses.Possible fix
Take the branch only when the key is one
_get_uncommon_lines()produced:Happy to PR against
develop.