mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Let ls work on absolute paths
This commit is contained in:
2 files changed
+16
-9
No files matched your search
@@ -131,10 +131,19 @@ describe('LsCommand', () => {
|
||||
expect(result.stderr).toContain('No such file or directory');
|
||||
});
|
||||
|
||||
it('should reject absolute paths', async () => {
|
||||
it('should handle absolute paths', async () => {
|
||||
vi.mocked(mockFS.stat).mockResolvedValue({
|
||||
isDirectory: () => true,
|
||||
isFile: () => false,
|
||||
});
|
||||
vi.mocked(mockFS.readdir).mockResolvedValue([
|
||||
{ name: 'file1.txt', isDirectory: () => false, isFile: () => true },
|
||||
]);
|
||||
|
||||
const result = await lsCommand.execute(['/absolute/path'], testCwd);
|
||||
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.stderr).toContain('absolute paths are not supported');
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(mockFS.stat).toHaveBeenCalledWith('/absolute/path');
|
||||
expect(result.stdout).toContain('file1.txt');
|
||||
});
|
||||
});
|
||||
@@ -28,12 +28,10 @@ export class LsCommand implements ShellCommand {
|
||||
|
||||
for (const path of targetPaths) {
|
||||
try {
|
||||
// Handle absolute paths
|
||||
if (path.startsWith('/') || path.startsWith('\\') || /^[A-Za-z]:[\\/]/.test(path)) {
|
||||
return createErrorResult(`${this.name}: absolute paths are not supported: ${path}`);
|
||||
}
|
||||
|
||||
const absolutePath = join(cwd, path);
|
||||
// Determine the absolute path
|
||||
const absolutePath = path.startsWith('/') || path.startsWith('\\') || /^[A-Za-z]:[\\/]/.test(path)
|
||||
? path // Already absolute
|
||||
: join(cwd, path); // Make relative path absolute
|
||||
const stats = await this.fs.stat(absolutePath);
|
||||
|
||||
if (stats.isFile()) {
|
||||
|
||||
Reference in new issue
Block a user