fix: add bounds check in ProcessSnippetInjection to prevent IndexOutOfRangeException#323
Merged
MIchaelMainer merged 2 commits intoOneDrive:masterfrom Mar 17, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a crash in the snippet-injection pipeline by preventing an out-of-bounds array access when a markdown tab section terminator (---) is the last line of a file.
Changes:
- Add a bounds check before reading
originalFileContents[currentIndex + 1]when detecting the end of a tab section. - Add unit tests covering the EOF
---scenario and an additional “comment on first line” edge-case scenario.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| ApiDoctor.Console/Program.cs | Adds bounds check in the tab-section end detection to avoid IndexOutOfRangeException. |
| ApiDoctor.Console.UnitTests/ProcessSnippetInjectionTests.cs | Adds tests intended to reproduce the EOF --- crash scenario and cover an additional edge case. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…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 both by: - Setting snippetsTabSectionEndLine to currentIndex + 1 so the '---' line is always included in the splice range. - Adding a bounds check before peeking at the next line. - Clamping the FileSplicer offset when insertionLine falls past the end of the array after the splice. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
acf2c81 to
65605e5
Compare
MIchaelMainer
approved these changes
Mar 17, 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.
Problem
The
Generate snippetspipeline step crashes with:Root Cause
In
ProcessSnippetInjection, theFindEndOfTabSectionstate accessesoriginalFileContents[currentIndex + 1]without bounds checking. When a markdown file's tab section terminator---is the very last line with no trailing blank line, this throws anIndexOutOfRangeException.Fix
Added a bounds check (\currentIndex + 1 < originalFileContents.Length) before accessing the next array element.
Tests
equestStartLine - 1\ edge case