Skip to content

Commit 7302de4

Browse files
committed
fix(vnext): reject invalid CTE cursor positions
1 parent 8a15723 commit 7302de4

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

src/vnext/__tests__/cte-layout.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,9 +1180,17 @@ describe("bounded CTE layout", () => {
11801180
names: [{ quoted: false, value: "outer_cte" }],
11811181
},
11821182
});
1183-
for (const position of [-1, Number.NaN, text.length + 1]) {
1183+
for (const position of [
1184+
-1,
1185+
0.5,
1186+
text.length - 0.5,
1187+
Number.NaN,
1188+
Number.POSITIVE_INFINITY,
1189+
text.length + 1,
1190+
]) {
11841191
expect(visibleSqlCtesAt(layout, position)).toMatchObject({
11851192
ctes: [],
1193+
issues: [],
11861194
quality: "recovered",
11871195
shadowing: { coverage: "unknown" },
11881196
});

src/vnext/cte-layout.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,18 @@ export function visibleSqlCtesAt(
16021602
layout: Exclude<SqlCteLayout, { status: "unavailable" }>,
16031603
position: number,
16041604
): SqlCteVisibility {
1605+
if (
1606+
!Number.isSafeInteger(position) ||
1607+
position < 0 ||
1608+
position > layout.statementLength
1609+
) {
1610+
return Object.freeze({
1611+
ctes: Object.freeze([]),
1612+
issues: Object.freeze([]),
1613+
quality: "recovered",
1614+
shadowing: Object.freeze({ coverage: "unknown" }),
1615+
});
1616+
}
16051617
const namespace = new Map<
16061618
number,
16071619
SqlCteDeclaration | null
@@ -1612,11 +1624,7 @@ export function visibleSqlCtesAt(
16121624
position > layout.exactThrough ||
16131625
(position === layout.exactThrough &&
16141626
layout.exactThrough < layout.statementLength);
1615-
let shadowingUnknown =
1616-
!Number.isSafeInteger(position) ||
1617-
position < 0 ||
1618-
position > layout.statementLength ||
1619-
beyondExactCoverage;
1627+
let shadowingUnknown = beyondExactCoverage;
16201628

16211629
if (beyondExactCoverage) {
16221630
for (const issue of layout.issues) {

0 commit comments

Comments
 (0)