mirror of
https://github.com/morluto/rea
synced 2026-10-28 15:07:26 -04:00
ef535b81fe
Move hasScheme/stripQueryAndFragment/admitsCanonicalPathSyntax plus looksExternal into domain/artifactPathSyntax with the deliberate policy-divergence table (artifact root vs allowedOrigins vs exact-origin fetch). Adopt in JavaScriptArtifactPathResolution and the Electron native specifier check with characterization tests. Policy unification tracked in #829.
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
admitsCanonicalPathSyntax,
|
|
hasScheme,
|
|
looksExternal,
|
|
stripQueryAndFragment,
|
|
} from "./artifactPathSyntax.js";
|
|
|
|
describe("artifact path syntax", () => {
|
|
it("detects URI schemes without matching bare paths", () => {
|
|
expect(hasScheme("https://example.test/app.js")).toBe(true);
|
|
expect(hasScheme("file:///app.js")).toBe(true);
|
|
expect(hasScheme("node:fs")).toBe(true);
|
|
expect(hasScheme("./relative.js")).toBe(false);
|
|
expect(hasScheme("/absolute.js")).toBe(false);
|
|
expect(hasScheme("app.js")).toBe(false);
|
|
});
|
|
|
|
it("flags scheme-qualified and protocol-relative references as external", () => {
|
|
expect(looksExternal("https://example.test/app.js")).toBe(true);
|
|
expect(looksExternal("//example.test/app.js")).toBe(true);
|
|
expect(looksExternal("./app.js")).toBe(false);
|
|
expect(looksExternal("/app.js")).toBe(false);
|
|
});
|
|
|
|
it("strips queries and fragments in fragment-first order", () => {
|
|
expect(stripQueryAndFragment("./app.js?token=secret#hash")).toBe(
|
|
"./app.js",
|
|
);
|
|
expect(stripQueryAndFragment("./app.js#hash?token=secret")).toBe(
|
|
"./app.js",
|
|
);
|
|
expect(stripQueryAndFragment("./app.js")).toBe("./app.js");
|
|
});
|
|
|
|
it("rejects NUL, backslash, and encoded dot/separator bytes", () => {
|
|
expect(admitsCanonicalPathSyntax("./app.js")).toBe(true);
|
|
expect(admitsCanonicalPathSyntax("dir\\app.js")).toBe(false);
|
|
expect(admitsCanonicalPathSyntax("dir\0app.js")).toBe(false);
|
|
expect(admitsCanonicalPathSyntax("./%2e%2e/secret.js")).toBe(false);
|
|
expect(admitsCanonicalPathSyntax("./%2Fapp.js")).toBe(false);
|
|
expect(admitsCanonicalPathSyntax("./%5capp.js")).toBe(false);
|
|
});
|
|
});
|