mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
fix(javascript): preserve incomplete package and artifact identity facts (#10032)
fix(javascript): preserve artifact identity and manifest uncertainty
This commit is contained in:
1 parent
15d08235e1
commit
20aeaf110f
6 files changed
+133
-73
No files matched your search
@@ -128,17 +128,15 @@ const EXTENSIONS = [
|
||||
// A private URL namespace for logical artifact paths, including root packages.
|
||||
// Encode inventory segments so filename punctuation remains literal in the base.
|
||||
const PACKAGE_ARTIFACT_ROOT_URL = new URL("file:///rea-artifact/");
|
||||
const encodePackageMetadataUrl = (path: string): URL =>
|
||||
new URL(
|
||||
path.split("/").map(encodeURIComponent).join("/"),
|
||||
PACKAGE_ARTIFACT_ROOT_URL,
|
||||
);
|
||||
const encodeArtifactPathUrl = (path: string, root: URL): URL =>
|
||||
new URL(path.split("/").map(encodeURIComponent).join("/"), root);
|
||||
// URL identity cannot represent lone UTF-16 surrogates. Use request-local
|
||||
// opaque segments only for structural admission, never inventory lookup. A
|
||||
// target cannot spell these identities after URL's tab/newline preprocessing.
|
||||
const packageMetadataUrl = (
|
||||
const artifactPathUrl = (
|
||||
path: string,
|
||||
relativeTarget: string,
|
||||
root: URL = PACKAGE_ARTIFACT_ROOT_URL,
|
||||
): Result<
|
||||
URL,
|
||||
{
|
||||
@@ -148,7 +146,7 @@ const packageMetadataUrl = (
|
||||
}
|
||||
> => {
|
||||
try {
|
||||
return ok(encodePackageMetadataUrl(path));
|
||||
return ok(encodeArtifactPathUrl(path, root));
|
||||
} catch (cause: unknown) {
|
||||
if (!(cause instanceof URIError)) throw cause;
|
||||
const reserved = new Set(
|
||||
@@ -175,9 +173,9 @@ const packageMetadataUrl = (
|
||||
})
|
||||
.join("/");
|
||||
return err({
|
||||
structuralUrl: new URL(structuralPath, PACKAGE_ARTIFACT_ROOT_URL),
|
||||
structuralUrl: new URL(structuralPath, root),
|
||||
structuralSegments,
|
||||
limitation: `Package metadata path ${JSON.stringify(path)} contains an unpaired UTF-16 surrogate and cannot be represented as a URL.`,
|
||||
limitation: `Artifact path ${JSON.stringify(path)} contains an unpaired UTF-16 surrogate and cannot be represented as a URL.`,
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -680,7 +678,7 @@ const contextualCandidate = (
|
||||
return unresolvedCandidate("rejected", [
|
||||
"The module URL escapes the selected logical artifact root.",
|
||||
]);
|
||||
const sourceUrl = packageMetadataUrl(input.sourcePath, declared);
|
||||
const sourceUrl = artifactPathUrl(input.sourcePath, declared);
|
||||
const base = sourceUrl.ok
|
||||
? sourceUrl.value
|
||||
: sourceUrl.error.structuralUrl;
|
||||
@@ -728,11 +726,15 @@ const contextualCandidate = (
|
||||
// after dot segments reach the root. Parse before percent decoding so an
|
||||
// encoded drive-like filename stays literal. The synthetic base establishes
|
||||
// only this ambiguity; it does not establish the source's runtime scheme.
|
||||
const sourceUrlPath = input.sourcePath
|
||||
.split("/")
|
||||
.map(encodeURIComponent)
|
||||
.join("/");
|
||||
const fileReference = URL.parse(declared, `file:///${sourceUrlPath}`);
|
||||
const sourceUrl = artifactPathUrl(
|
||||
input.sourcePath,
|
||||
declared,
|
||||
new URL("file:///"),
|
||||
);
|
||||
const fileReference = URL.parse(
|
||||
declared,
|
||||
sourceUrl.ok ? sourceUrl.value : sourceUrl.error.structuralUrl,
|
||||
);
|
||||
if (fileReference === null)
|
||||
return unresolvedCandidate("rejected", [
|
||||
"The URL reference cannot be parsed as a URL.",
|
||||
@@ -746,6 +748,13 @@ const contextualCandidate = (
|
||||
return unresolvedCandidate("rejected", [
|
||||
"The URL reference path percent-decodes to NUL or to bytes that are not UTF-8.",
|
||||
]);
|
||||
if (
|
||||
!sourceUrl.ok &&
|
||||
fileReference.pathname
|
||||
.split("/")
|
||||
.some((segment) => sourceUrl.error.structuralSegments.has(segment))
|
||||
)
|
||||
return unresolvedCandidate("unavailable", [sourceUrl.error.limitation]);
|
||||
const candidate = urlRelativeCandidate(
|
||||
posix.dirname(input.sourcePath),
|
||||
decoded,
|
||||
@@ -1125,7 +1134,7 @@ const resolveLegacyEsmSubpath = (
|
||||
depth--;
|
||||
} else if (segment !== ".") depth++;
|
||||
}
|
||||
const metadataUrl = packageMetadataUrl(
|
||||
const metadataUrl = artifactPathUrl(
|
||||
posix.join(directory, "package.json"),
|
||||
subpath,
|
||||
);
|
||||
@@ -1952,7 +1961,7 @@ const selectStringPackageTarget = (
|
||||
`contains forbidden path segment ${JSON.stringify(forbidden)} before URL normalization`,
|
||||
mapKind,
|
||||
);
|
||||
const metadataUrl = packageMetadataUrl(packagePath, value);
|
||||
const metadataUrl = artifactPathUrl(packagePath, value);
|
||||
const packageUrl = metadataUrl.ok
|
||||
? metadataUrl.value
|
||||
: metadataUrl.error.structuralUrl;
|
||||
|
||||
Reference in new issue
Block a user