pi-ext
bugabingas pi extensions
owned by bugabinga
fix(the-system): close Phase 2 review bypasses
cfb2f8d776fc4f766b0b8d2e0ff93d117ceea481
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
Browse filesCompare with HEAD
Changed files (2)
extensions/the-system/__tests__/documents.test.ts
Modified 122 + it(
"rejects duplicate config keys", ()
=> 126 + '{"prefix":"PX","prefix":"AB","schemaVersion":1,"styleVersion":1}',
128 + (error
: unknown)
=> 129 + error
instanceof SystemDocumentError && 130 + error.
code === "config.duplicate-key",
123 134 [
"malformed JSON",
"{"],
238 249 ]
as const)(
"parses exact metadata %s", (json, expected)
=> 239 250 assert.
deepEqual(
parseDocumentMetadata(
shell(json),
"PX"), expected));
252 + it(
"wraps malformed metadata JSON", ()
=> {
255 + parseDocumentMetadata(
256 + shell(
'{"id":"PX-SPEC-001","type":"spec","\\uZZZZ":true}'),
259 + (error
: unknown)
=> 260 + error
instanceof SystemDocumentError && 261 + error.
code === "metadata.invalid-json",
265 + it(
"ignores metadata blocks inside HTML comments", ()
=> {
266 + const html
= `${shell('{"id":"PX-SPEC-001","type":"spec"}')}<!-- <script type="application/json" id="system-meta">{}</script> -->`;
267 + assert.
deepEqual(
parseDocumentMetadata(html,
"PX"), {
242 274 [
"missing block",
'<!doctype html><html lang="en"></html>'],
401 433 validateAuthoredHtml(
"doc.html", html).
some((item)
=> item.
code === code),
404 - it(
"allows remote HTTPS navigation anchors", ()
=> {
436 + it(
"ignores shell and forbidden tags inside HTML comments", ()
=> {
405 437 const html
= shell(
406 438 '{"id":"PX-SPEC-001","type":"spec"}',
407 - '<header><h1>X</h1></header><main><section><a href="https://example.com/reference">Reference</a></section></main>',
439 + "<!-- <header><main><section><iframe></iframe></section></main></header> -->",
409 - assert.
deepEqual(
validateAuthoredHtml(
"doc.html", html), []);
441 + const codes
= validateAuthoredHtml(
"doc.html", html).
map(
442 + ({ code })
=> code,
444 + assert.
ok(codes.
includes(
"document.semantic-shell"));
445 + assert.
ok(
!codes.
includes(
"document.forbidden-tag"));
449 + [
"missing head close",
"</head>"],
450 + [
"missing body close",
"</body>"],
451 + [
"missing html close",
"</html>"],
452 + [
"missing header close",
"</header>"],
453 + [
"missing main close",
"</main>"],
454 + [
"missing section close",
"</section>"],
455 + ]
as const)(
"requires a complete shell: %s", (_name, removed)
=> {
456 + const findings
= validateAuthoredHtml(
458 + shell(
'{"id":"PX-SPEC-001","type":"spec"}').
replace(removed,
""),
463 + code
=== "document.structure" || code
=== "document.semantic-shell",
470 + "unquoted executable URL",
471 + "<a href=javascript:alert(1)>X</a>",
472 + "document.executable-url",
475 + "encoded executable URL with control whitespace",
476 + '<a href="java	script:alert(1)">X</a>',
477 + "document.executable-url",
480 + "unquoted remote src",
481 + "<img src=https://example.com/a.png>",
482 + "document.remote-resource",
485 + "encoded remote srcset",
486 + '<img srcset="/local.png 1x, https://example.com/a.png 2x">',
487 + "document.remote-resource",
491 + '<video poster="//example.com/poster.png"></video>',
492 + "document.remote-resource",
495 + "resource-bearing href",
496 + '<link rel="preload" href="https://example.com/font.woff2">',
497 + "document.remote-resource",
499 + ]
as const)(
"rejects %s", (_name, markup, code)
=> {
500 + const html
= shell(
501 + '{"id":"PX-SPEC-001","type":"spec"}',
502 + `<header><h1>X</h1></header><main><section>${markup}</section></main>`,
505 + validateAuthoredHtml(
"doc.html", html).
some(
506 + (finding)
=> finding.
code === code,
511 + it(
"allows quoted and unquoted remote HTTPS navigation anchors", ()
=> {
512 + for (
const anchor
of [
513 + '<a href="https://example.com/reference">Reference</a>',
514 + "<a href=https://example.com/reference>Reference</a>",
516 + const html
= shell(
517 + '{"id":"PX-SPEC-001","type":"spec"}',
518 + `<header><h1>X</h1></header><main><section>${anchor}</section></main>`,
520 + assert.
deepEqual(
validateAuthoredHtml(
"doc.html", html), []);
461 573 assert.
deepEqual(result.diagnostics, []);
464 - it(
"sorts stable duplicate, filename, dangling, and forbidden-edge diagnostics", ()
=> {
576 + it(
"excludes HTML- and filename-invalid documents from graph edges", ()
=> {
577 + const invalidSpec
= source(
581 + '{"id":"PX-SPEC-009","type":"spec"}',
583 + invalidSpec.html
= invalidSpec.html.
replace(
585 + "<!-- <header> -->",
587 + const invalidPlan
= source(
591 + '{"id":"PX-PLAN-002","type":"plan","spec":"PX-SPEC-404"}',
593 + invalidPlan.html
= invalidPlan.html.
replace(
"<main>",
"");
594 + const invalidFilenamePlan
= source(
597 + "invalid-filename-source",
598 + '{"id":"PX-PLAN-003","type":"plan","spec":"PX-SPEC-405"}',
600 + const result
= indexDocuments(
607 + '{"id":"PX-SPEC-010","type":"spec"}',
612 + "references-invalid-html",
613 + '{"id":"PX-PLAN-001","type":"plan","spec":"PX-SPEC-009"}',
618 + "references-invalid-filename",
619 + '{"id":"PX-PLAN-005","type":"plan","spec":"PX-SPEC-010"}',
622 + invalidFilenamePlan,
626 + const invalidSourcePaths
= new Set(
628 + .
filter(({ metadata })
=> 629 + [
"PX-PLAN-002",
"PX-PLAN-003"].
includes(metadata.
id),
631 + .
map(({ path })
=> path),
634 + result.diagnostics.
some(
635 + ({ code, path })
=> 636 + code
=== "document.filename" && path.
includes(
"PX-SPEC-002"),
640 + result.diagnostics.
some(
641 + ({ code, path })
=> 642 + code
=== "document.semantic-shell" && path.
includes(
"PX-SPEC-009"),
645 + for (
const planId
of [
"PX-PLAN-001",
"PX-PLAN-005"])
647 + result.diagnostics.
some(
648 + ({ code, path })
=> 649 + code
=== "graph.dangling-reference" && path.
includes(planId),
652 + for (
const path
of invalidSourcePaths)
654 + result.diagnostics.
some(
655 + (item)
=> item.path
=== path
&& item.
code.
startsWith(
"document."),
659 + !result.diagnostics.
some(
660 + ({ code, path })
=> 661 + code.
startsWith(
"graph.")
&& invalidSourcePaths.
has(path),
666 + it(
"sorts stable filename, dangling, and forbidden-edge diagnostics", ()
=> {
465 667 const result
= indexDocuments(
521 723 .
map(({ code })
=> code),
524 - result.diagnostics.
some(
526 - item.
code === "graph.duplicate-id" && 527 - item.message.
includes(
"PX-SPEC-001"),
726 + !result.diagnostics.
some((item)
=> item.
code === "graph.duplicate-id"),
531 729 result.diagnostics.
some((item)
=> item.
code === "document.filename"),
extensions/the-system/documents.ts
Modified165 165 throw new SystemDocumentError(
"config.invalid-json",
"Invalid config JSON");
167 + const duplicates
= duplicateTopLevelKeys(source);
168 + if (duplicates.
length)
169 + throw new SystemDocumentError(
170 + "config.duplicate-key",
171 + `Duplicate config keys: ${duplicates.join(", ")}`,
167 173 const value
= objectValue(parsed,
"Config");
168 174 exactKeys(value, [
"prefix",
"schemaVersion",
"styleVersion"]);
169 175 if (
typeof value.
prefix !== "string" || !PREFIX.
test(value.
prefix)) {
314 +type HtmlTag = Readonly<{
319 + attributes
: ReadonlyMap<
string,
string | undefined>;
322 +const withoutHtmlComments = (html
: string)
=> 323 + html.
replace(
/<!--[\s\S]*?(?:-->|$)/g, (comment)
=> 324 + comment.
replace(
/[^\r\n]/g,
" "),
327 +const scanAttributes = (
329 +)
: ReadonlyMap<
string,
string | undefined>
=> {
330 + const attributes
= new Map<
string,
string | undefined>();
332 + while (index
< source.
length) {
333 + while (
/\s|\//.
test(source[index]
?? "")) index
+= 1;
334 + const start
= index;
335 + while (
!/[\s=/>]/.
test(source[index]
?? ">")) index
+= 1;
336 + if (start
=== index)
break;
337 + const name
= source.
slice(start, index).
toLowerCase();
338 + while (
/\s/.
test(source[index]
?? "")) index
+= 1;
339 + let value
: string | undefined;
340 + if (source[index]
=== "=") {
342 + while (
/\s/.
test(source[index]
?? "")) index
+= 1;
344 + source[index]
=== '"' || source[index]
=== "'" 347 + const valueStart
= index;
349 + while (index
< source.
length && source[index]
!== quote) index
+= 1;
351 + while (index
< source.
length && !/[\s>]/.
test(source[index]))
353 + value
= source.
slice(valueStart, index);
354 + if (quote
&& source[index]
=== quote) index
+= 1;
356 + if (
!attributes.
has(name)) attributes.
set(name, value);
361 +const scanHtmlTags = (html
: string)
: readonly HtmlTag[]
=> {
362 + const source
= withoutHtmlComments(html);
363 + const tags
: HtmlTag[]
= [];
365 + while (index
< source.
length) {
366 + const start
= source.
indexOf(
"<", index);
367 + if (start
< 0)
break;
368 + let cursor
= start
+ 1;
369 + const closing
= source[cursor]
=== "/";
370 + if (closing) cursor
+= 1;
371 + while (
/\s/.
test(source[cursor]
?? "")) cursor
+= 1;
372 + const nameStart
= cursor;
373 + while (
/[A-Za-z0-9:-]/.
test(source[cursor]
?? "")) cursor
+= 1;
374 + if (cursor
=== nameStart) {
378 + const name
= source.
slice(nameStart, cursor).
toLowerCase();
379 + let quote
: string | undefined;
381 + for (; end
< source.
length; end
+= 1) {
382 + const character
= source[end];
384 + if (character
=== quote) quote
= undefined;
385 + }
else if (character
=== '"' || character
=== "'") quote
= character;
386 + else if (character
=== ">")
break;
388 + if (end
>= source.
length)
break;
394 + attributes: closing
396 + : scanAttributes(source.
slice(cursor, end)),
403 +const namedEntities
: Readonly<
Record<
string,
string>>
= {
413 +const decodeBasicEntities = (value
: string)
=> 415 + /&(?:#(\d+)|#x([\da-f]+)|([a-z][a-z\d]+));?/gi,
416 + (entity, decimal
: string, hexadecimal
: string, named
: string)
=> {
417 + if (named)
return namedEntities[named.
toLowerCase()]
?? entity;
418 + const point
= Number.
parseInt(decimal
?? hexadecimal, decimal
? 10 : 16);
420 + return String.
fromCodePoint(point);
426 +const attributeValue = (tag
: HtmlTag, name
: string)
=> {
427 + const value
= tag.
attributes.
get(name);
428 + return value
=== undefined ? undefined : decodeBasicEntities(value);
430 +const normalizedUrl = (value
: string)
=> 431 + decodeBasicEntities(value)
432 + .
replace(
/[\u0000-\u001f\u007f-\u009f]/g,
"")
435 +const scriptBlocks = (html
: string, tags
= scanHtmlTags(html))
=> {
436 + const blocks
: { tag
: HtmlTag; content
: string }[]
= [];
437 + for (
let index
= 0; index
< tags.
length; index
+= 1) {
438 + const tag
= tags[index];
439 + if (tag.
name !== "script" || tag.closing)
continue;
442 + .
find((item)
=> item.
name === "script" && item.closing);
443 + if (close) blocks.
push({ tag, content: html.
slice(tag.end, close.
start) });
308 448 const metadataScripts = (html
: string)
=> 309 - [
...html.
matchAll(
/<script\b([^>]*)>([\s\S]*?)<\/script\s*>/gi)].
filter(
311 - /\bid\s*=\s*(["'])system-meta\1/i.
test(match[
1])
&& 312 - /\btype\s*=\s*(["'])application\/json\1/i.
test(match[
1]),
449 + scriptBlocks(html).
filter(
451 + attributeValue(tag,
"id")?.
toLowerCase()
=== "system-meta" && 452 + attributeValue(tag,
"type")?.
toLowerCase()
=== "application/json",
315 455 export function parseDocumentMetadata(
322 462 "metadata.block",
323 463 `Expected exactly one system-meta block; received ${blocks.length}`,
325 - const json
= blocks[
0][
2].
trim();
326 - const duplicates
= duplicateTopLevelKeys(json);
327 - if (duplicates.
length)
328 - throw new SystemDocumentError(
329 - "metadata.duplicate-key",
330 - `Duplicate metadata keys: ${duplicates.join(", ")}`,
465 + const json
= blocks[
0].
content.
trim();
332 466 let parsed
: unknown;
467 + let duplicates
: string[];
334 469 parsed
= JSON.
parse(json);
470 + duplicates
= duplicateTopLevelKeys(json);
336 472 throw new SystemDocumentError(
337 473 "metadata.invalid-json",
338 474 "Invalid system metadata JSON",
477 + if (duplicates.
length)
478 + throw new SystemDocumentError(
479 + "metadata.duplicate-key",
480 + `Duplicate metadata keys: ${duplicates.join(", ")}`,
341 482 const value
= objectValue(parsed,
"Metadata");
342 483 if (
typeof value.
id !== "string" || typeof value.
type !== "string")
343 484 throw new SystemDocumentError(
446 587 )
: Diagnostic => ({ code, path, message });
447 -const count = (source
: string, expression
: RegExp)
=> 448 - [
...source.
matchAll(expression)].
length;
588 +const tagsNamed = (tags
: readonly HtmlTag[], name
: string, closing
= false)
=> 589 + tags.
filter((tag)
=> tag.
name === name
&& tag.closing
=== closing);
590 +const isExecutableUrl = (value
: string)
=> 591 + /^(?:javascript|vbscript|data):/i.
test(
normalizedUrl(value));
592 +const isRemoteUrl = (value
: string)
=> 593 + /^(?:https?:|\/\/)/i.
test(
normalizedUrl(value));
594 +const srcsetUrls = (value
: string)
=> 595 + decodeBasicEntities(value)
597 + .
map((candidate)
=> candidate.
trim().
split(
/\s+/)[
0]
?? "");
598 +const srcsetHasRemoteUrl = (value
: string)
=> 599 + srcsetUrls(value).
some(isRemoteUrl);
450 601 export function validateAuthoredHtml(
451 602 filename
: string,
453 604 )
: readonly Diagnostic[] {
454 605 const findings
: Diagnostic[]
= [];
455 - const requireOne = (code
: string, expression
: RegExp, message
: string)
=> {
456 - if (
count(html, expression)
!== 1)
457 - findings.
push(
diagnostic(code, filename, message));
606 + const cleanHtml
= withoutHtmlComments(html);
607 + const tags
= scanHtmlTags(html);
608 + const opening = (name
: string)
=> tagsNamed(tags, name);
609 + const closing = (name
: string)
=> tagsNamed(tags, name,
true);
610 + const add = (code
: string, message
: string)
=> 611 + findings.
push(
diagnostic(code, filename, message));
613 + if (
!/^<!doctype html>/i.
test(cleanHtml.
trimStart()))
614 + add(
"document.doctype",
"Document must begin with HTML doctype");
616 + const htmlOpen
= opening(
"html");
617 + const htmlClose
= closing(
"html");
618 + const headOpen
= opening(
"head");
619 + const headClose
= closing(
"head");
620 + const bodyOpen
= opening(
"body");
621 + const bodyClose
= closing(
"body");
623 + htmlOpen.
length !== 1 || 624 + htmlClose.
length !== 1 || 625 + headOpen.
length !== 1 || 626 + headClose.
length !== 1 || 627 + bodyOpen.
length !== 1 || 628 + bodyClose.
length !== 1 || 629 + !(htmlOpen[
0]?.
start < headOpen[
0]?.
start)
|| 630 + !(headOpen[
0]?.
start < headClose[
0]?.
start)
|| 631 + !(headClose[
0]?.
start < bodyOpen[
0]?.
start)
|| 632 + !(bodyOpen[
0]?.
start < bodyClose[
0]?.
start)
|| 633 + !(bodyClose[
0]?.
start < htmlClose[
0]?.
start)
636 + "document.structure",
637 + "Document requires one complete html, head, and body structure",
641 + htmlOpen.
length !== 1 || 642 + attributeValue(htmlOpen[
0],
"lang")?.
toLowerCase()
!== "en" 644 + add(
"document.language",
"Document requires one html lang=en root");
646 + const meta
= opening(
"meta");
649 + (tag)
=> attributeValue(tag,
"charset")?.
toLowerCase()
=== "utf-8",
652 + add(
"document.charset",
"Document requires one UTF-8 charset meta");
656 + attributeValue(tag,
"name")?.
toLowerCase()
=== "viewport" && 657 + /^width=device-width,\s*initial-scale=1$/i.
test(
658 + attributeValue(tag,
"content")
?? "",
662 + add(
"document.viewport",
"Document requires one viewport meta");
664 + const titleOpen
= opening(
"title");
665 + const titleClose
= closing(
"title");
667 + titleOpen.
length !== 1 || 668 + titleClose.
length !== 1 || 669 + titleOpen[
0].end
>= titleClose[
0].
start || 670 + !html.
slice(titleOpen[
0].end, titleClose[
0].
start).
trim()
672 + add(
"document.title",
"Document requires one nonempty title");
674 + const stylesheets
= opening(
"link").
filter((tag)
=> 675 + (
attributeValue(tag,
"rel")
?? "")
678 + .
includes(
"stylesheet"),
681 + stylesheets.
length !== 1 || 682 + attributeValue(stylesheets[
0],
"href")
!== "../system.css" 685 + "document.stylesheet",
686 + "Document requires exactly one ../system.css stylesheet",
690 + header: { open:
opening(
"header"), close:
closing(
"header") },
691 + main: { open:
opening(
"main"), close:
closing(
"main") },
692 + section: { open:
opening(
"section"), close:
closing(
"section") },
459 - if (
!/^<!doctype html>/i.
test(html.
trimStart()))
462 - "document.doctype",
464 - "Document must begin with HTML doctype",
468 - "document.language",
469 - /<html\b[^>]*\blang\s*=\s*(["'])en\1[^>]*>/gi,
470 - "Document requires one html lang=en root",
473 - "document.charset",
474 - /<meta\b[^>]*\bcharset\s*=\s*(["'])?utf-8\1[^>]*>/gi,
475 - "Document requires one UTF-8 charset meta",
478 - "document.viewport",
479 - /<meta\b[^>]*\bname\s*=\s*(["'])viewport\1[^>]*\bcontent\s*=\s*(["'])width=device-width,\s*initial-scale=1\2[^>]*>/gi,
480 - "Document requires one viewport meta",
484 - /<title>\s*[^<\s][^<]*<\/title>/gi,
485 - "Document requires one nonempty title",
488 - "document.stylesheet",
489 - /<link\b(?=[^>]*\brel\s*=\s*(["'])stylesheet\1)(?=[^>]*\bhref\s*=\s*(["'])\.\.\/system\.css\2)[^>]*>/gi,
490 - "Document requires exactly ../system.css",
492 - if (
count(html,
/<link\b[^>]*\brel\s*=\s*(["'])stylesheet\1[^>]*>/gi)
!== 1)
495 - "document.stylesheet",
497 - "Additional or missing stylesheets are forbidden",
500 - for (
const tag
of [
"header",
"main",
"section"]
as const)
694 + for (
const name
of [
"header",
"main",
"section"]
as const) {
695 + const pair
= semantic[name];
697 + pair.open.
length !== 1 || 698 + pair.close.
length !== 1 || 699 + pair.open[
0].
start >= pair.close[
0].
start 702 + "document.semantic-shell",
703 + `Document requires one complete ${name} element`,
707 + bodyOpen.
length === 1 && 708 + bodyClose.
length === 1 && 709 + semantic.header.open.
length === 1 && 710 + semantic.header.close.
length === 1 && 711 + semantic.main.open.
length === 1 && 712 + semantic.main.close.
length === 1 && 713 + semantic.section.open.
length === 1 && 714 + semantic.section.close.
length === 1 && 716 + bodyOpen[
0].
start < semantic.header.open[
0].
start && 717 + semantic.header.close[
0].
start < semantic.main.open[
0].
start && 718 + semantic.main.open[
0].
start < semantic.section.open[
0].
start && 719 + semantic.section.close[
0].
start < semantic.main.close[
0].
start && 720 + semantic.main.close[
0].
start < bodyClose[
0].
start 502 724 "document.semantic-shell",
503 - new RegExp(
`<${tag}\\b`,
"gi"),
504 - `Document requires one ${tag} element`,
506 - if (
/<\/?(?:iframe|object|embed)\b/i.
test(html))
509 - "document.forbidden-tag",
511 - "iframe, object, and embed are forbidden",
514 - if (
/<meta\b[^>]*\bhttp-equiv\s*=\s*(["'])refresh\1/i.
test(html))
517 - "document.meta-refresh",
519 - "Meta refresh is forbidden",
522 - if (
/\son[a-z]+\s*=/i.
test(html))
525 - "document.event-handler",
527 - "Event-handler attributes are forbidden",
725 + "Document requires header then main with one contained section",
728 + if (tags.
some((tag)
=> [
"iframe",
"object",
"embed"].
includes(tag.
name)))
729 + add(
"document.forbidden-tag",
"iframe, object, and embed are forbidden");
531 - /\b(?:href|src|action|formaction|xlink:href)\s*=\s*(["'])\s*(?:javascript|vbscript|data):/i.
test(
732 + (tag)
=> attributeValue(tag,
"http-equiv")?.
toLowerCase()
=== "refresh",
537 - "document.executable-url",
539 - "Executable URL schemes are forbidden",
542 - if (
/<script\b[^>]*\bsrc\s*=/i.
test(html))
545 - "document.external-script",
547 - "External script sources are forbidden",
735 + add(
"document.meta-refresh",
"Meta refresh is forbidden");
551 - /<(?:img|audio|video|source|track)\b[^>]*\bsrc\s*=\s*(["'])https?:/i.
test(
740 + [
...tag.
attributes].
some(([name])
=> /^on[a-z]+$/i.
test(name)),
557 - "document.remote-resource",
559 - "Remote media resources are forbidden",
743 + add(
"document.event-handler",
"Event-handler attributes are forbidden");
745 + const urlAttributes
= new Set([
754 + let executableUrl
= false;
755 + let remoteResource
= false;
756 + for (
const tag
of tags) {
757 + if (tag.closing)
continue;
758 + for (
const [name, rawValue]
of tag.
attributes) {
759 + if (
!urlAttributes.
has(name)
|| rawValue
=== undefined)
continue;
761 + isExecutableUrl(rawValue)
|| 762 + (name
=== "srcset" && srcsetUrls(rawValue).
some(isExecutableUrl))
764 + executableUrl
= true;
766 + ((name
=== "src" || name
=== "poster")
&& isRemoteUrl(rawValue))
|| 767 + (name
=== "srcset" && srcsetHasRemoteUrl(rawValue))
|| 768 + ((name
=== "href" || name
=== "xlink:href")
&& 769 + tag.
name !== "a" && 770 + tag.
name !== "area" && 771 + isRemoteUrl(rawValue))
773 + remoteResource
= true;
777 + add(
"document.executable-url",
"Executable URL schemes are forbidden");
778 + if (remoteResource)
779 + add(
"document.remote-resource",
"Remote runtime resources are forbidden");
780 + if (
opening(
"script").
some((tag)
=> tag.
attributes.
has(
"src")))
781 + add(
"document.external-script",
"External script sources are forbidden");
782 + if (
/(?:@import|url\s*\(\s*["']?\s*(?:https?:|data:))/i.
test(cleanHtml))
784 + "document.css-resource",
785 + "CSS imports and remote/data URLs are forbidden",
562 - if (
/(?:@import|url\s*\(\s*["']?\s*(?:https?:|data:))/i.
test(html))
565 - "document.css-resource",
567 - "CSS imports and remote/data URLs are forbidden",
570 - const executable
= [
571 - ...html.
matchAll(
/<script\b([^>]*)>([\s\S]*?)<\/script\s*>/gi),
788 + const executable
= scriptBlocks(html, tags)
574 - (match)
=> !/\btype\s*=\s*(["'])application\/json\1/i.
test(match[
1]),
791 + attributeValue(tag,
"type")?.
toLowerCase()
!== "application/json",
576 - .
map((match)
=> match[
2])
793 + .
map(({ content })
=> content)
579 796 /\b(?:fetch|XMLHttpRequest|WebSocket|EventSource|importScripts|localStorage|sessionStorage|indexedDB)\b/.
test(
582 799 /\bimport\s*\(/.
test(executable)
586 - "document.active-api",
588 - "Network, import, and browser storage APIs are forbidden",
802 + "document.active-api",
803 + "Network, import, and browser storage APIs are forbidden",
591 805 return findings.
sort(compareDiagnostics);
630 844 ): DocumentIndex {
631 845 const documents
: DocumentRecord[]
= [];
846 + const graphEligible
: DocumentRecord[]
= [];
632 847 const diagnostics
: Diagnostic[]
= [];
633 848 for (
const item
of [
...sources].
sort((left, right)
=> 634 849 left.path.
localeCompare(right.path),
636 - diagnostics.
push(
...validateAuthoredHtml(item.path, item.html));
851 + const htmlDiagnostics
= validateAuthoredHtml(item.path, item.html);
852 + diagnostics.
push(
...htmlDiagnostics);
638 854 const metadata
= parseDocumentMetadata(item.html, prefix);
855 + let filenameValid
= true;
640 857 validateFilename(item.path, metadata, prefix);
641 858 }
catch (error) {
859 + filenameValid
= false;
642 860 diagnostics.
push(
643 861 diagnostic(
"document.filename", item.path, (error
as Error).message),
646 - documents.
push({ path: item.path, metadata });
864 + const record
= { path: item.path, metadata };
865 + documents.
push(record);
866 + if (filenameValid
&& htmlDiagnostics.
length === 0)
867 + graphEligible.
push(record);
647 868 }
catch (error) {
648 869 const value
= error
as SystemDocumentError;
649 870 diagnostics.
push(
658 879 const groups
= new Map<
string,
DocumentRecord[]>();
659 - for (
const document
of documents)
880 + for (
const document
of graphEligible)
660 881 groups.
set(
document.metadata.
id, [
661 882 ...(groups.
get(
document.metadata.
id)
?? []),
679 900 .
filter(([, records])
=> records.
length === 1)
680 901 .
map(([id, records])
=> [id, records[
0]]),
682 - for (
const document
of documents) {
903 + for (
const document
of graphEligible) {
683 904 for (
const [targetId, expectedType]
of references(
document.metadata)) {
684 905 const referencedType
= parseDocumentId(targetId, prefix).
type;
685 906 const target
= unique.
get(targetId);