From c578452db6defb5ed6cd79b785a2d0db72fa3cd7 Mon Sep 17 00:00:00 2001 From: Tyagiquamar Date: Tue, 25 Aug 2026 16:29:55 +0530 Subject: [PATCH] fix: resolve Windows-style backslash paths in input resolution --- src/press-resolver.ts | 5 +++-- test/environment.test.ts | 3 ++- test/press-resolver.test.ts | 4 ++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/press-resolver.ts b/src/press-resolver.ts index 4ef431f..2e5d522 100644 --- a/src/press-resolver.ts +++ b/src/press-resolver.ts @@ -29,7 +29,8 @@ 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. */ @@ -37,7 +38,7 @@ 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"); } // --------------------------------------------------------------------------- diff --git a/test/environment.test.ts b/test/environment.test.ts index 67cde3d..9d4645c 100644 --- a/test/environment.test.ts +++ b/test/environment.test.ts @@ -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", () => { @@ -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 () => { diff --git a/test/press-resolver.test.ts b/test/press-resolver.test.ts index d0f35f7..65d872f 100644 --- a/test/press-resolver.test.ts +++ b/test/press-resolver.test.ts @@ -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); });