Skip to content

Find code by asking what it does. A CLI for coding agents that uses Jev to discover relevant files and source context.

fix: ignore relative XDG config and cache paths

LIES7cf4917294d6
diff --git a/packages/core/src/storage.ts b/packages/core/src/storage.ts
index 515428b..c90fbd3 100644
--- a/packages/core/src/storage.ts
+++ b/packages/core/src/storage.ts
@@ -1,5 +1,5 @@
import { homedir } from "node:os";
-import { join } from "node:path";
+import { isAbsolute, join } from "node:path";
/** The one source of Jevgrep's config and cache locations; filesystem policy protects the same paths. */
export function storageDirectory(
@@ -8,7 +8,7 @@ export function storageDirectory(
platform: NodeJS.Platform = process.platform,
) {
const xdg = kind === "config" ? env.XDG_CONFIG_HOME : env.XDG_CACHE_HOME;
- if (xdg) return join(xdg, "jevgrep");
+ if (xdg && isAbsolute(xdg)) return join(xdg, "jevgrep");
if (platform === "win32") {
const base = kind === "config" ? env.APPDATA : env.LOCALAPPDATA;
return join(
diff --git a/packages/core/test/storage.test.ts b/packages/core/test/storage.test.ts
index 8abf1d3..3c318fe 100644
--- a/packages/core/test/storage.test.ts
+++ b/packages/core/test/storage.test.ts
@@ -11,6 +11,23 @@ test("XDG locations win on every platform", () => {
}
});
+test("relative XDG locations are ignored on every platform", () => {
+ const env = {
+ XDG_CONFIG_HOME: "relative/config",
+ XDG_CACHE_HOME: "../cache",
+ APPDATA: "/roaming",
+ LOCALAPPDATA: "/local",
+ };
+ for (const platform of ["linux", "darwin", "win32"] as const) {
+ expect(storageDirectory("config", env, platform)).toBe(
+ join(platform === "win32" ? "/roaming" : join(homedir(), ".config"), "jevgrep"),
+ );
+ expect(storageDirectory("cache", env, platform)).toBe(
+ join(platform === "win32" ? "/local" : join(homedir(), ".cache"), "jevgrep"),
+ );
+ }
+});
+
test("Windows uses APPDATA for config and LOCALAPPDATA for cache", () => {
const env = { APPDATA: "/roaming", LOCALAPPDATA: "/local" };
expect(storageDirectory("config", env, "win32")).toBe(join("/roaming", "jevgrep"));