Commit 5bcf11e
authored
fix: skip whitespace-only lines in _concatenate_shell_commands to prevent stray semicolons (caldera#3097) (#48)
* fix: skip whitespace-only lines in _concatenate_shell_commands to prevent stray semicolons
When the prereq block (ending with 'fi;') is combined with the ability command via
'dep_construct \n command', a whitespace-only line between them caused
_concatenate_shell_commands to append '; ' after it, producing commands like
'fi; ; ip neighbour show' (issue #3097 on mitre/caldera).
Filtering out whitespace-only lines before concatenation eliminates the stray separator.
A regression test is included.
* fix: update regression test to use double-space pattern that triggers the actual bug
The original regression test used a single-space whitespace line (' \n ')
between the prereq block and the command, but the real bug (issue #3097)
produced 'fi; ; ip neighbour show' with double spaces. Update the test
input to ' \n ' and the assertion to check for '; ;' so the test
accurately reproduces the triggering condition.
* fix: use regex to assert against general whitespace-between-semicolons pattern
Replace the exact string check for '; ;' (double-space only) with a
regex assertion re.search(r';\s+;', result) so the regression test
catches any amount of whitespace between consecutive semicolons, not
just the double-space case from the original bug report.1 parent 880231f commit 5bcf11e
2 files changed
Lines changed: 19 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | | - | |
| 192 | + | |
| 193 | + | |
193 | 194 | | |
194 | | - | |
195 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
178 | 179 | | |
179 | 180 | | |
180 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
181 | 195 | | |
182 | 196 | | |
183 | 197 | | |
| |||
0 commit comments