Files
hyperframes/scripts/registry-cdn-pins.test.ts
T
Michael WangandClaude Opus 5.5 24508ce2da fix: harden docs snippets, SVG sanitizer, lint regexes, GSAP writers and registry pins (#7512)
* fix(docs): escape catalog preview values and the install command's --vars argument

The catalog preview embeds variable values as JSON that cannot close a
script element or attribute, accepts value messages only from the page
that embeds it, and reads only declared ids with primitive values from
the link. The install command shell-quotes its --vars JSON and keeps
only variable-id keys with primitive values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(core): fold CSS line endings before decoding escapes in the SVG sanitizer

A browser folds CR LF, CR and form feed into one newline before it reads
CSS escapes, so the whitespace after a hex escape can be a CR LF pair.
The sanitizer now does the same, so an escaped function name split by a
line ending is checked under its real name. The media-use bundle is
regenerated from the source.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(lint): match template ids and CSS rules in linear time

A getElementById template literal is matched against document ids with
an in-order indexOf scan instead of a regex of joined wildcards, so the
time no longer grows with the number of placeholders. The CSS rule
scanners only start a match at the beginning of a brace-free run, which
finds the same rules without rescanning long brace-less text. Lint
results on every HTML file in the repository are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(parsers): keep GSAP writer output inside its script element

String literals and quoted keys the GSAP writers emit now encode a
script closer or comment opener as \u003c, so a value can no longer end
the inline script that holds the timeline. Strings without those
sequences are written exactly as before. The writers also refuse a tween
method outside set, to, from and fromTo, and a motion path whose
coordinates or curviness are not numbers, since both are emitted as code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(scripts): confine registry asset hosting to files inside the item

The asset hosting script now refuses a manifest path that leaves the
item directory or reaches its file through a symlink, before anything is
read, staged, uploaded or removed. A repository test fails when the
registry tracks a symlink or a manifest path that leaves its item.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(registry): pin the map blocks' d3 and atlas files to exact versions

The five map blocks load d3 7.9.2, the build the d3@7 range serves today,
with a subresource integrity hash, and fetch us-atlas 3.0.1 and
world-atlas 2.0.2, the files their ranges serve today. The bytes are
unchanged, so the blocks render the same. A repository test fails when a
registry item names an npm CDN package by range, tag or no version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(registry): pin map blocks to d3 7.9.0

7.9.0 has been the stable release since 2024; 7.9.1 and 7.9.2 were published days ago. Pin the
long-standing version, with its subresource integrity hash.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(registry): keep the map block PR source-only and formatted

Restore the generated catalog pages and payloads, which the catalog
publish job regenerates from the item sources. Name the us-atlas URL
in us-map-flow so the call fits on one line and formatting is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(scripts): check registry asset containment with one prefix test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(lint): scan simple CSS rules in linear time

The two CSS-rule scans in the gsap rules took a body that could cross
'{', so a closed style of many '{' with no '}' rescanned to its end from
every brace. A scanner now returns the same selector and body pairs and
remembers the next '}', so each scan is linear. Findings are identical
on every tracked HTML file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(core): label the form-feed sanitizer case as a guard

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 20:01:29 +00:00

43 lines
1.7 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
import { readFileSync } from "node:fs";
import { join, resolve } from "node:path";
/** Registry items load npm packages from a CDN only at an exact version, so the bytes cannot change under them. */
const ROOT = resolve(import.meta.dirname, "..");
const NPM_CDN =
/(?:cdn\.jsdelivr\.net\/npm|unpkg\.com)\/((?:@[^/@"'`\s]+\/)?[^/@"'`\s)]+)(@[^/"'`\s)]*)?/g;
const EXACT = /^@\d+\.\d+\.\d+(?:-[\w.]+)?$/;
function floatingCdnReferences(text: string): string[] {
return [...text.matchAll(NPM_CDN)]
.filter((match) => !EXACT.test(match[2] ?? ""))
.map((match) => match[0]);
}
test("a range, tag or missing version is reported", () => {
assert.deepEqual(
floatingCdnReferences(
`<script src="https://cdn.jsdelivr.net/npm/d3@7/dist/d3.min.js"></script>
fetch("https://unpkg.com/us-atlas/states-10m.json");
import x from "https://cdn.jsdelivr.net/npm/@scope/pkg@latest/+esm";
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>`,
),
["cdn.jsdelivr.net/npm/d3@7", "unpkg.com/us-atlas", "cdn.jsdelivr.net/npm/@scope/pkg@latest"],
);
});
test("every npm CDN reference in a registry item names an exact version", () => {
const files = execFileSync("git", ["ls-files", "-z", "registry"], {
cwd: ROOT,
encoding: "utf-8",
})
.split("\0")
.filter((file) => /\.(html|js|mjs|json)$/.test(file));
const floating = files.flatMap((file) =>
floatingCdnReferences(readFileSync(join(ROOT, file), "utf-8")).map((ref) => `${file}: ${ref}`),
);
assert.deepEqual(floating, []);
});