Skip to content

CFE-2663: Select empty region at end of file when select_end_match_eof is set#6208

Open
nickanderson wants to merge 2 commits into
cfengine:masterfrom
nickanderson:CFE-2663/master
Open

CFE-2663: Select empty region at end of file when select_end_match_eof is set#6208
nickanderson wants to merge 2 commits into
cfengine:masterfrom
nickanderson:CFE-2663/master

Conversation

@nickanderson

Copy link
Copy Markdown
Member

When an insert_lines (or other edit_line) promise uses select_region with select_end_match_eof => "true", and the select_start delimiter matches the last line of the file, SelectRegion() rejects the (empty) region at EOF and the edit fails with "could not select an edit region". This makes the final section of an INI-style file impossible to populate once it is empty, which is exactly what set_variable_values_ini() / manage_variable_values_ini() hit in the wild.

This PR is structured for TDD:

  1. First commit adds a failing acceptance test (31_tickets/CFE-2663/) that inserts a key into an empty trailing section. It fails today.
  2. A follow-up commit makes SelectRegion() honor select_end_match_eof for an empty region at end of file, turning the test green.

Ticket: https://northerntech.atlassian.net/browse/CFE-2663

An insert_lines promise using select_region with select_end_match_eof
cannot select the region of the final section when that section header
is the last line of the file. The region is empty and sits at the end
of the file, SelectRegion() rejects it, and the insertion fails with
"could not select an edit region".

This test fails today and will pass once SelectRegion() honors
select_end_match_eof for an empty region at end of file.

Ticket: CFE-2663
Changelog: None
Signed-off-by: Nick Anderson <nick@cmdln.org>
When select_region matched a start delimiter on the last line of the
file and include_start_delimiter was false, SelectRegion() rejected the
region as an "empty region at the end of file" and the edit failed with
"could not select an edit region". This happened even when
select_end_match_eof was true, which is meant to let the region extend
to the end of the file.

Now the empty region at end of file is accepted when select_end_match_eof
is set, so a trailing section (its header being the last line of the
file) can still be populated by insert_lines and similar promises.

Ticket: CFE-2663
Changelog: Title
Signed-off-by: Nick Anderson <nick@cmdln.org>
@nickanderson

Copy link
Copy Markdown
Member Author

@cf-bottom jenkins please

@nickanderson nickanderson marked this pull request as ready for review July 1, 2026 23:04
@cf-bottom

Copy link
Copy Markdown

@nickanderson

Copy link
Copy Markdown
Member Author

@cf-bottom jenkins please

@cf-bottom

Copy link
Copy Markdown

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants