fix(registry): reject non-numeric caption-data versions; boot fetch never clobbers a manual attach

Two review findings on the caption-data runtime, applied to all 5 templates:
- hfValidate's version gate used Math.floor(Number(v)) > HF_CONTRACT_VERSION,
  and Number("v2") is NaN — NaN comparisons are always false, so malformed
  versions slid through with no unsupported-version signal. An explicit
  Number.isFinite check closes it.
- hfBoot's sibling-fetch .then called hfAttach unconditionally; a manual
  window.__HF_CAPTION_ATTACH__ call landing while the fetch or fonts.ready
  was still pending got clobbered by the late boot payload. Boot now yields
  if a timeline already exists.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
vanceingalls
2026-07-24 05:55:21 +00:00
co-authored by Claude Fable 5
parent e2846eb7cc
commit 5c2981d066
5 changed files with 55 additions and 10 deletions
@@ -200,8 +200,13 @@
function hfValidate(data) {
if (!data || typeof data !== "object") return { ok: false, reason: "not-an-object" };
if (data.version != null && Math.floor(Number(data.version)) > HF_CONTRACT_VERSION) {
return { ok: false, reason: "unsupported-version" };
if (data.version != null) {
// Number("v2") is NaN and NaN > x is always false — an explicit
// finite check keeps malformed versions from slipping past the gate.
var hfVersion = Number(data.version);
if (!Number.isFinite(hfVersion) || Math.floor(hfVersion) > HF_CONTRACT_VERSION) {
return { ok: false, reason: "unsupported-version" };
}
}
if (!Array.isArray(data.segments) || data.segments.length === 0) {
return { ok: false, reason: "no-segments" };
@@ -616,6 +621,10 @@
var ready =
document.fonts && document.fonts.ready ? document.fonts.ready : Promise.resolve();
ready.then(function () {
// A manual window.__HF_CAPTION_ATTACH__ call that lands while the
// sibling fetch / fonts.ready are still pending must win — never
// clobber it with the late-arriving boot payload.
if (hfCurrentTimeline) return;
hfAttach(data);
});
}