Environment
- Python version: 3.12.13
- netutils version: 1.19.1
Expected Behavior
A line that is_banner_start() accepts should be parseable by regex_banner.
Observed Behavior
They disagree, and the whole config is lost rather than one line.
is_banner_start() matches the stripped line (line.lstrip().startswith(...)), while CiscoConfigParser.regex_banner requires banner at column 0:
^(banner\s+\S+|\s*vacant-message)\s+(?P<banner_delimiter>\^C|.)
An indented banner is therefore detected as a banner start, fails to resolve a delimiter, and the banner_end setter raises. The exception leaves __init__, so one such line makes the entire config unparseable.
Two hints that this is an oversight rather than intent: in that pattern the vacant-message alternative allows \s* and the banner one does not; and ASAConfigParser parses an indented banner, including the one shipped at tests/unit/mock/config/parser/base/cisco_asa/asa_nested_banner_sent.txt, while IOS, NX-OS and EOS raise on the same input.
Steps to Reproduce
-
pip install netutils==1.19.1
-
Run:
from netutils.config.parser import IOSConfigParser
IOSConfigParser("group-policy P attributes\n banner value hello\n")
# ValueError: There was an error parsing your banner, the end of the banner could not be found
ASAConfigParser on that same input returns ['group-policy P attributes', ' banner value hello']. The sample is ASA syntax, chosen because netutils already ships a fixture for it; the point is that the two functions disagree, not that the line is valid IOS.
Possible fixes
Allow leading whitespace in regex_banner, or stop stripping in is_banner_start(). If the former, note the delimiter group . also matches the first character of a following word, so \^C|[^\w\s] may be wanted with it.
Happy to PR against develop.
Environment
Expected Behavior
A line that
is_banner_start()accepts should be parseable byregex_banner.Observed Behavior
They disagree, and the whole config is lost rather than one line.
is_banner_start()matches the stripped line (line.lstrip().startswith(...)), whileCiscoConfigParser.regex_bannerrequiresbannerat column 0:An indented banner is therefore detected as a banner start, fails to resolve a delimiter, and the
banner_endsetter raises. The exception leaves__init__, so one such line makes the entire config unparseable.Two hints that this is an oversight rather than intent: in that pattern the
vacant-messagealternative allows\s*and thebannerone does not; andASAConfigParserparses an indented banner, including the one shipped attests/unit/mock/config/parser/base/cisco_asa/asa_nested_banner_sent.txt, while IOS, NX-OS and EOS raise on the same input.Steps to Reproduce
pip install netutils==1.19.1Run:
ASAConfigParseron that same input returns['group-policy P attributes', ' banner value hello']. The sample is ASA syntax, chosen because netutils already ships a fixture for it; the point is that the two functions disagree, not that the line is valid IOS.Possible fixes
Allow leading whitespace in
regex_banner, or stop stripping inis_banner_start(). If the former, note the delimiter group.also matches the first character of a following word, so\^C|[^\w\s]may be wanted with it.Happy to PR against
develop.