fix(openclaw): normalize Windows skill-loader URLs before fileURLToPath (#5679)

This commit is contained in:
Rod Boev
2026-06-25 16:36:11 +05:30
committed by GitHub
parent b91c745fbc
commit 1f66aadfa3
2 changed files with 37 additions and 2 deletions
@@ -4,10 +4,12 @@
import { describe, it, expect } from "vitest";
import {
safePath,
normalizeModuleUrlToPath,
loadSkill,
loadTriagePrompt,
loadCompactTriagePrompt,
} from "./skill-loader.ts";
import { fileURLToPath, pathToFileURL } from "node:url";
// ---------------------------------------------------------------------------
// safePath — path containment
@@ -74,6 +76,31 @@ describe("loadSkill path traversal", () => {
});
});
describe("normalizeModuleUrlToPath", () => {
it("normalizes raw Windows paths before fileURLToPath conversion", () => {
const rawWindowsMetaUrl = "C:\\Users\\example\\openclaw\\index.ts";
const result = normalizeModuleUrlToPath(rawWindowsMetaUrl);
// Assert the decoded property directly rather than reconstructing via the function body
expect(typeof result).toBe("string");
expect(result).not.toContain("%5C");
});
it("leaves already-correct file URLs unchanged", () => {
const fileMetaUrl = "file:///C:/Users/example/openclaw/index.ts";
const expected = fileURLToPath(fileMetaUrl);
expect(normalizeModuleUrlToPath(fileMetaUrl)).toBe(expected);
});
it.skipIf(process.platform === "win32")(
"passes POSIX absolute paths through unchanged",
() => {
const posixPath = "/home/user/openclaw/index.ts";
expect(normalizeModuleUrlToPath(posixPath)).toBe(posixPath);
},
);
});
describe("loadCompactTriagePrompt", () => {
it("keeps the core triage instructions without inlining the full skill body", () => {
const prompt = loadCompactTriagePrompt();