fix: guard against invalid line in provideAltTextQuickFix (fixes #318227) (#318228)

The provideAltTextQuickFix method calls document.lineAt(range.start.line)
without validating that the line number is within bounds. When the document
is modified between when VS Code computes the range and when the code action
provider executes, an out-of-bounds line number causes 'Illegal value for
`line`' to be thrown.

Add a bounds check before calling lineAt() so the method returns early
instead of throwing.

Co-authored-by: vs-code-engineering[bot] <122617954+vs-code-engineering[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
vs-code-engineering[bot]
2026-05-25 20:11:25 +00:00
committed by GitHub
parent c298595b23
commit f5a135b01f
@@ -136,6 +136,9 @@ export class QuickFixesProvider implements vscode.CodeActionProvider {
}
private provideAltTextQuickFix(document: vscode.TextDocument, range: vscode.Range): ImageCodeAction | undefined {
if (range.start.line < 0 || range.start.line >= document.lineCount) {
return;
}
const currentLine = document.lineAt(range.start.line).text;
const generateImagePath = extractImageAttributes(currentLine);
const refineImagePath = extractImageAttributes(currentLine, true);