fix: moving header sections when inserting snippets#328
Merged
MIchaelMainer merged 2 commits intoOneDrive:masterfrom Mar 19, 2026
Merged
Conversation
…fRangeException When a markdown file's tab section terminator '---' is the very last line with no trailing blank line, two issues occurred: 1. Accessing originalFileContents[currentIndex + 1] without bounds checking caused an IndexOutOfRangeException crash. 2. The '---' line was not included in the removable splice range, leaving a stray terminator in the output. Fix by setting snippetsTabSectionEndLine to currentIndex + 1 as an exclusive end so the '---' line is always included in the splice range. Remove the trailing blank line peek which was only needed as a workaround for the old inclusive index and which, when combined with the +1 fix, would over-remove and displace subsequent headers like '### Response' into the tab section. Clamp the FileSplicer offset when insertionLine falls past the end of the array after the splice (EOF edge case). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes edge cases in markdown snippet-tab replacement when the tab terminator (---) appears at EOF (no trailing blank line), preventing crashes and ensuring the terminator is properly removed without displacing subsequent headers.
Changes:
- Adjust tab-section end handling to treat the
---line as part of the removable splice range (exclusive end index) and remove a bounds-unsafe “peek” for a trailing blank line. - Add/adjust unit tests for EOF terminator behavior and for ensuring following headers (e.g.,
### Response) are not moved into the tab section. - Update the “comment on first line” test to assert current behavior (no injection) instead of only asserting “no throw”.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| ApiDoctor.Console/Program.cs | Updates tab-section end detection to avoid out-of-range access and ensure --- is included in the splice range. |
| ApiDoctor.Console.UnitTests/ProcessSnippetInjectionTests.cs | Refines and expands tests around EOF terminators and header displacement scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
MIchaelMainer
approved these changes
Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a markdown file's tab section terminator '---' is the very last line with no trailing blank line, two issues occurred:
Fix by setting snippetsTabSectionEndLine to currentIndex + 1 as an exclusive end so the '---' line is always included in the splice range. Remove the trailing blank line peek which was only needed as a workaround for the old inclusive index and which, when combined with the +1 fix, would over-remove and displace subsequent headers like '### Response' into the tab section.
Clamp the FileSplicer offset when insertionLine falls past the end of the array after the splice (EOF edge case).