Skip to content

Do not treat an indented banner as the start of a banner - #909

Open
ggiesen wants to merge 1 commit into
networktocode:developfrom
ggiesen:fix-indented-banner
Open

Do not treat an indented banner as the start of a banner#909
ggiesen wants to merge 1 commit into
networktocode:developfrom
ggiesen:fix-indented-banner

Conversation

@ggiesen

@ggiesen ggiesen commented Sep 10, 2026

Copy link
Copy Markdown

Fixes #907.

is_banner_start() matches the stripped line, while the banner patterns anchor at the start of it. Where the two disagree the line cannot yield a delimiter, and the ValueError that follows leaves __init__, so one indented banner loses the whole config.

CiscoConfigParser.is_banner_start() now checks the line against its own regex_banner before accepting it, so the two agree by construction and each subclass keeps its own pattern. EOSConfigParser has no such pattern and matches its terminator by name, so it stops stripping instead. Both mirror ASAConfigParser, which already avoided this by not stripping in its own is_banner_start().

This takes the "don't recognise it" direction rather than "allow leading whitespace in the patterns". I tried the other one first: relaxing the anchors makes an indented banner value hello resolve h as its delimiter and then fail hunting for a terminator, which trades one exception for another. Removing the strip from the base class instead breaks hp_comware, since _HPEConfigParser relies on it for indented header lines.

Covers cisco_ios, cisco_nxos, cisco_iosxr and arista_eos. Tests assert both that the indented line no longer aborts the parse and that a real top-level banner still folds. 825 passed, 6 skipped; ruff, pylint and mypy clean.

is_banner_start matches the stripped line, while the banner patterns anchor at
the start of it. Where the two disagreed the line could not yield a delimiter,
and the ValueError that followed left __init__, so a single indented banner made
the whole configuration unparseable.

CiscoConfigParser now checks the line against its own regex_banner before
accepting it, so the two agree by construction and each subclass keeps its own
pattern. EOSConfigParser has no such pattern and matches the terminator by name,
so it stops stripping instead. Both mirror ASAConfigParser, which already avoided
this by not stripping in its own is_banner_start.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Indented banner raises ValueError and loses the whole config: is_banner_start and regex_banner disagree

1 participant