Skip to content

FortinetConfigParser: an object name containing '[' raises ValueError: Input line is malformed. #908

Description

@ggiesen

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

  1. pip install netutils==1.19.1

  2. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions