Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/cli/src/serve/fs/workspace-file-system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,27 @@ describe('WorkspaceFileSystem - write/edit', () => {
}
});

it('rejects non-positive-integer opts.limit with parse_error', async () => {
const target = path.join(h.workspace, 'v.txt');
await fsp.writeFile(target, 'a\nb\nc\n');
const r = await h.fs.resolve('v.txt', 'read');
for (const bad of [
Infinity,
-Infinity,
Number.MAX_SAFE_INTEGER + 1,
0,
-1,
1.5,
NaN,
]) {
const err = await h.fs
.readText(r, { limit: bad })
.catch((e: unknown) => e);
expect(isFsError(err)).toBe(true);
expect((err as { kind: string }).kind).toBe('parse_error');
}
});

it('records matchedIgnore on edit() audit (parity with readText/writeText)', async () => {
const ignore = new Ignore().add(['*.log']);
h = await makeHarness({ ignore });
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/src/serve/fs/workspace-file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,15 @@ class WorkspaceFileSystemImpl implements WorkspaceFileSystem {
`line must be a positive integer, got ${opts.line}`,
);
}
if (
opts.limit !== undefined &&
(!Number.isSafeInteger(opts.limit) || opts.limit < 1)
) {
throw new FsError(
'parse_error',
`limit must be a positive integer, got ${opts.limit}`,
);
}
const snapshot = await readTextSnapshotFromResolvedFile(p, opts);
const ignoreVerdict = shouldIgnore(
p,
Expand Down
Loading