Skip to content

Commit 8579e43

Browse files
committed
check parent range when creating selection range, microsoft#67872
1 parent a2f6ec6 commit 8579e43

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/vs/workbench/api/node/extHostTypes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,10 @@ export class SelectionRange {
11031103
constructor(range: Range, parent?: SelectionRange) {
11041104
this.range = range;
11051105
this.parent = parent;
1106+
1107+
if (parent && !parent.range.contains(this.range)) {
1108+
throw new Error('Invalid argument: parent must contain this range');
1109+
}
11061110
}
11071111
}
11081112

src/vs/workbench/test/electron-browser/api/extHostLanguageFeatures.test.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,19 +1119,15 @@ suite('ExtHostLanguageFeatures', function () {
11191119
});
11201120

11211121
test('Selection Ranges, bad data', async () => {
1122-
disposables.push(extHost.registerSelectionRangeProvider(defaultExtension, defaultSelector, new class implements vscode.SelectionRangeProvider {
1123-
provideSelectionRanges() {
1124-
return [
1125-
new types.SelectionRange(new types.Range(0, 10, 0, 18),
1126-
new types.SelectionRange(new types.Range(0, 11, 0, 18))),
1127-
];
1128-
}
1129-
}));
11301122

1131-
await rpcProtocol.sync();
1123+
try {
1124+
let _a = new types.SelectionRange(new types.Range(0, 10, 0, 18),
1125+
new types.SelectionRange(new types.Range(0, 11, 0, 18))
1126+
);
1127+
assert.ok(false, String(_a));
1128+
} catch (err) {
1129+
assert.ok(true);
1130+
}
11321131

1133-
provideSelectionRanges(model, [new Position(1, 17)], CancellationToken.None).then(ranges => {
1134-
assert.equal(ranges.length, 0);
1135-
});
11361132
});
11371133
});

0 commit comments

Comments
 (0)