Skip to content
Open
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
5 changes: 3 additions & 2 deletions src/press-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ export interface ResolvedPressCall {
// ---------------------------------------------------------------------------

/**
* Determine if a value looks like a resolvable file path (contains `/` and ends with `.md`, excluding URLs).
* Determine if a value looks like a resolvable file path (contains a path
* separator and ends with `.md`, excluding URLs).
* @param value - The input string to check.
* @returns `true` if the value should be read from disk during input resolution.
*/
export function isResolvablePath(value: string): boolean {
if (value.startsWith("http://") || value.startsWith("https://")) {
return false;
}
return value.includes("/") && value.endsWith(".md");
return (value.includes("/") || value.includes("\\")) && value.endsWith(".md");
}

// ---------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion test/environment.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, expect, it } from "vitest";
import { join } from "node:path";
import { JsEnvironment, SANDBOX_BUILTINS } from "../src/environment.js";

describe("JsEnvironment", () => {
Expand Down Expand Up @@ -67,7 +68,7 @@ describe("JsEnvironment", () => {
it("require: node built-ins", async () => {
const env = new JsEnvironment();
const result = await env.exec('const path = require("path"); console.log(path.join("a", "b"))');
expect(result.output).toBe("a/b");
expect(result.output).toBe(join("a", "b"));
});

it("require: rejects non-builtins", async () => {
Expand Down
4 changes: 4 additions & 0 deletions test/press-resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ describe("isResolvablePath", () => {
expect(isResolvablePath("/absolute/path/to/file.md")).toBe(true);
});

it("returns true for a Windows-style absolute path", () => {
expect(isResolvablePath("C:\\Users\\me\\docs\\file.md")).toBe(true);
});

it("returns false for a bare word like 'haiku'", () => {
expect(isResolvablePath("haiku")).toBe(false);
});
Expand Down