mirror of
https://github.com/morluto/rea
synced 2026-10-28 06:46:47 -04:00
fix(javascript): decode literal file URLs at the path boundary
Decode known literal file URLs with explicit path semantics before assigning filesystem-expression context. Preserve unknown drive, UNC, dynamic and malformed inputs and existing source-relative projection. Validation: 64 path-owner and 26 filesystem application tests pass. Fixes #2561. Based on #3147. Co-authored-by: João Pedro de Faria <jpdefo7@hotmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { posix } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { parseExpression } from "@babel/parser";
|
||||
import { describe, expect, it } from "vitest";
|
||||
@@ -207,6 +208,32 @@ describe("inert JavaScript path resolution", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
"file:///app/preload%20file.js",
|
||||
"file:///app/%E2%9C%93.js",
|
||||
"file:///app/preload.js?query=1#fragment",
|
||||
])("decodes literal file URL %s as a filesystem expression", (url) => {
|
||||
assertPathProjection(
|
||||
`fileURLToPath(${JSON.stringify(url)})`,
|
||||
fileURLToPath(url, { windows: false }),
|
||||
"filesystem-expression",
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
'fileURLToPath("file:///app/%2Fpreload.js")',
|
||||
'fileURLToPath("file:///app/%5Cpreload.js")',
|
||||
'fileURLToPath("file:///app/%")',
|
||||
'fileURLToPath("file:///C:/app/preload.js")',
|
||||
'fileURLToPath("file://remote/share/preload.js")',
|
||||
'fileURLToPath("file:///app/preload.js", options)',
|
||||
"fileURLToPath(selectedUrl)",
|
||||
])("leaves platform-dependent or invalid %s unknown", (expression) =>
|
||||
expect(
|
||||
staticPath(parseExpression(expression, { sourceType: "module" })),
|
||||
).toBeUndefined(),
|
||||
);
|
||||
|
||||
const analyzePathConsumers = (expression: string) => {
|
||||
const property = `preload: ${expression}`;
|
||||
const genericPrefix = "const options = { ";
|
||||
|
||||
Reference in New Issue
Block a user