Merge branch 'main' of github.com:getpaseo/paseo
This commit is contained in:
@@ -98,6 +98,27 @@ describe("file explorer service", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("allows home to be the scoped root for tilde file previews", async () => {
|
||||
const root = await createHomeTempDir(".paseo-file-explorer-home-root-");
|
||||
|
||||
try {
|
||||
const filePath = path.join(root, "sample.txt");
|
||||
await writeFile(filePath, "hello from home root\n", "utf-8");
|
||||
|
||||
const tildePath = `~/${path.relative(os.homedir(), filePath)}`;
|
||||
const result = await readExplorerFile({
|
||||
root: "~",
|
||||
relativePath: tildePath,
|
||||
});
|
||||
|
||||
expect(result.kind).toBe("text");
|
||||
expect(result.path).toBe(path.relative(os.homedir(), filePath).split(path.sep).join("/"));
|
||||
expect(result.content).toBe("hello from home root\n");
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects ~-prefixed paths that resolve outside the workspace", async () => {
|
||||
const root = await mkdtemp(path.join(os.tmpdir(), "paseo-file-explorer-outside-home-"));
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { constants, promises as fs } from "fs";
|
||||
import type { FileHandle } from "fs/promises";
|
||||
import path from "path";
|
||||
import { resolvePathFromBase } from "../path-utils.js";
|
||||
import { expandUserPath, resolvePathFromBase } from "../path-utils.js";
|
||||
|
||||
export type ExplorerEntryKind = "file" | "directory";
|
||||
export type ExplorerFileKind = "text" | "image" | "binary";
|
||||
@@ -276,7 +276,7 @@ async function resolveScopedPath({
|
||||
root,
|
||||
relativePath = ".",
|
||||
}: ScopedPathParams): Promise<ScopedPath> {
|
||||
const normalizedRoot = path.resolve(root);
|
||||
const normalizedRoot = expandUserPath(root);
|
||||
const requestedPath = resolvePathFromBase(normalizedRoot, relativePath);
|
||||
const relative = path.relative(normalizedRoot, requestedPath);
|
||||
|
||||
@@ -335,8 +335,8 @@ function isOutsideWorkspaceError(error: unknown): boolean {
|
||||
}
|
||||
|
||||
function normalizeRelativePath({ root, targetPath }: { root: string; targetPath: string }): string {
|
||||
const normalizedRoot = path.resolve(root);
|
||||
const normalizedTarget = path.resolve(targetPath);
|
||||
const normalizedRoot = expandUserPath(root);
|
||||
const normalizedTarget = expandUserPath(targetPath);
|
||||
const relative = path.relative(normalizedRoot, normalizedTarget);
|
||||
return relative === "" ? "." : relative.split(path.sep).join("/");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user