Skip to content

Commit ab8498a

Browse files
authored
1 parent 8d808bc commit ab8498a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/vs/editor/common/diff/standardLinesDiffComputer.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,35 @@ export class StandardLinesDiffComputer implements ILinesDiffComputer {
169169
}
170170
}
171171

172+
// Make sure all ranges are valid
173+
assertFn(() => {
174+
function validatePosition(pos: Position, lines: string[]): boolean {
175+
if (pos.lineNumber < 1 || pos.lineNumber > lines.length) { return false; }
176+
const line = lines[pos.lineNumber - 1];
177+
if (pos.column < 1 || pos.column > line.length + 1) { return false; }
178+
return true;
179+
}
180+
181+
function validateRange(range: LineRange, lines: string[]): boolean {
182+
if (range.startLineNumber < 1 || range.startLineNumber > lines.length + 1) { return false; }
183+
if (range.endLineNumberExclusive < 1 || range.endLineNumberExclusive > lines.length + 1) { return false; }
184+
return true;
185+
}
186+
187+
for (const c of changes) {
188+
if (!c.innerChanges) { return false; }
189+
for (const ic of c.innerChanges) {
190+
const valid = validatePosition(ic.modifiedRange.getStartPosition(), modifiedLines) && validatePosition(ic.modifiedRange.getEndPosition(), modifiedLines) &&
191+
validatePosition(ic.originalRange.getStartPosition(), originalLines) && validatePosition(ic.originalRange.getEndPosition(), originalLines);
192+
if (!valid) { return false; }
193+
}
194+
if (!validateRange(c.modifiedRange, modifiedLines) || !validateRange(c.originalRange, originalLines)) {
195+
return false;
196+
}
197+
}
198+
return true;
199+
});
200+
172201
return new LinesDiff(changes, moves, hitTimeout);
173202
}
174203

0 commit comments

Comments
 (0)