GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(lab-ops-hub): address Codex round-2 P2s on extractor parity (#569) · developing-today/code@17347f0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pkgs/lab-ops-hub
    • src
      • lib.ts
    • test
      • extractor-fixtures.json
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pkgs/lab-ops-hub/src/lib.ts‎

Copy file name to clipboardExpand all lines: pkgs/lab-ops-hub/src/lib.ts
+30-5Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,12 @@ export function decodeHtmlEntities(data: string): string {
528528
const code = Number.parseInt(body.slice(hex ? 2 : 1), hex ? 16 : 10);
529529
return String.fromCodePoint(normalizeNumericRef(code));
530530
}
531-
return NAMED_ENTITIES[body] ?? whole;
531+
// Own-property lookup only: a plain index would resolve inherited
532+
// Object properties (&constructor;, &toString;) to JavaScript
533+
// functions, where HTMLParser leaves unknown names literal.
534+
return Object.prototype.hasOwnProperty.call(NAMED_ENTITIES, body)
535+
? NAMED_ENTITIES[body]
536+
: whole;
532537
});
533538
}
534539

@@ -608,8 +613,19 @@ export function extractHtml(html: string): { title: string; links: number; text:
608613
}
609614
handleData(html.slice(i, i + close.index));
610615
i += close.index;
616+
// Consume the close tag here, tolerantly: HTMLParser accepts
617+
// recoverable end tags carrying trailing attributes
618+
// (</script foo>), which the strict end-tag pattern in the normal
619+
// path rejects -- skipDepth would stay set and the rest of the
620+
// document would be discarded.
621+
const closeTag = new RegExp(`</${cdataTag}[^>]*>`, "i").exec(html.slice(i));
622+
const closedTag = cdataTag;
611623
cdataTag = null;
612-
continue; // the close tag itself is parsed by the normal path
624+
if (closeTag !== null) {
625+
handleEndTag(closedTag);
626+
i += closeTag[0].length;
627+
}
628+
continue;
613629
}
614630
const lt = html.indexOf("<", i);
615631
if (lt === -1) {
@@ -655,12 +671,21 @@ export function extractHtml(html: string): { title: string; links: number; text:
655671
// attribute value end the tag early.
656672
let j = i + 1;
657673
let quote = "";
674+
let lastSig = "";
658675
while (j < n) {
659676
const ch = html[j];
660677
if (quote !== "") {
661-
if (ch === quote) quote = "";
662-
} else if (ch === '"' || ch === "'") quote = ch;
663-
else if (ch === ">") break;
678+
if (ch === quote) {
679+
quote = "";
680+
lastSig = ch;
681+
}
682+
} else if ((ch === '"' || ch === "'") && lastSig === "=") {
683+
// A quote opens a quoted value only where a value begins
684+
// (right after '='); a quote inside an unquoted value, as in
685+
// <a href=/it's>, is data, as HTMLParser tokenizes it.
686+
quote = ch;
687+
} else if (ch === ">") break;
688+
else if (!/\s/.test(ch)) lastSig = ch;
664689
j += 1;
665690
}
666691
if (j >= n) {
Collapse file

‎pkgs/lab-ops-hub/test/extractor-fixtures.json‎

Copy file name to clipboard
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"html":"<html><head><title>Hello</title></head><body><p>World</p><a href=\"/x\">one</a></body></html>","links":1,"name":"basic page: title, paragraph, one anchor","text":"World one","title":"Hello"},{"html":"<p>x</p><a>bare</a>","links":1,"name":"bare anchor counts (Worker regex <a\\s missed it)","text":"x bare","title":""},{"html":"<a/><a href=\"/y\">two</a>","links":2,"name":"self-closing anchor counts","text":"two","title":""},{"html":"<script>var s = '<a href=\"#\">fake</a>';</script><p>real</p>","links":0,"name":"anchor markup inside a script string does not count","text":"real","title":""},{"html":"<!-- <a href=\"#\">hidden</a> --><p>shown</p>","links":0,"name":"anchor markup inside a comment does not count","text":"shown","title":""},{"html":"<title>Fish &amp; Chips &#8212; &#x2014;</title><p>body</p>","links":0,"name":"title entities are decoded (Worker regex returned them raw)","text":"body","title":"Fish & Chips — —"},{"html":"<style>a { color: red; }</style><p>body</p>","links":0,"name":"style content does not leak into text (Worker fallback leaked it)","text":"body","title":""},{"html":"<title>My Title</title>loose text","links":0,"name":"title does not leak into text","text":"loose text","title":"My Title"},{"html":"<p>before</p><script>var a = '<a href=\"#\">x</a>';","links":0,"name":"unclosed script swallows the rest of the document","text":"before","title":""},{"html":"<p>keep</p><style>.a { color: blue; }","links":0,"name":"unclosed style swallows the rest of the document","text":"keep","title":""},{"html":"<p>a b\n\tc</p>","links":0,"name":"whitespace collapses across chunks","text":"a b c","title":""},{"html":"<TITLE>Caps</TITLE><A HREF=\"#\">U</A>","links":1,"name":"uppercase tags parse like lowercase","text":"U","title":"Caps"},{"html":"<p>&lt;tag&gt; &amp; &quot;q&quot; &nbsp; end</p>","links":0,"name":"entities in text are decoded, nbsp collapses as whitespace","text":"<tag> & \"q\" end","title":""},{"html":"a<b>bold</b>c","links":0,"name":"inline markup splits text into space-joined chunks","text":"a bold c","title":""},{"html":"<title>x <a href=\"#\">y</a> z</title><p>out</p>","links":0,"name":"title is raw text: markup inside is literal and anchors do not count","text":"out","title":"x <a href=\"#\">y</a> z"},{"html":"<a title=\"2 > 1\" href=\"#\">go</a>","links":1,"name":"quoted attribute value may contain >","text":"go","title":""},{"html":"<script>1</script><style>2</style><a href=\"#\">after</a>","links":1,"name":"script and style both skipped, anchors after them count","text":"after","title":""},{"name":"unquoted attribute value ending in / is not a self-closing tag (script stays raw text)","html":"<script src=/x/>var x=\"<a href=x>fake</a>\";</script><p>real</p>","title":"","links":0,"text":"real"},{"name":"comment terminated by --!> does not swallow the rest of the document","html":"<!-- migration note --!><h1>Article title</h1><p>Article body</p>","title":"","links":0,"text":"Article title Article body"},{"name":"abruptly closed empty comment <!--> does not swallow the rest of the document","html":"<!--><p>shown</p>","title":"","links":0,"text":"shown"},{"name":"numeric character reference in the C1 range is remapped (&#128; is the euro sign)","html":"<title>Price &#128;10</title><p>body</p>","title":"Price €10","links":0,"text":"body"},{"name":"numeric character references for NUL and a surrogate become U+FFFD","html":"<p>a&#0;b&#xD800;c</p>","title":"","links":0,"text":"a�b�c"},{"name":"out-of-range numeric character reference becomes U+FFFD","html":"<p>x&#x110000;y</p>","title":"","links":0,"text":"x�y"}]
1+
[{"html":"<html><head><title>Hello</title></head><body><p>World</p><a href=\"/x\">one</a></body></html>","links":1,"name":"basic page: title, paragraph, one anchor","text":"World one","title":"Hello"},{"html":"<p>x</p><a>bare</a>","links":1,"name":"bare anchor counts (Worker regex <a\\s missed it)","text":"x bare","title":""},{"html":"<a/><a href=\"/y\">two</a>","links":2,"name":"self-closing anchor counts","text":"two","title":""},{"html":"<script>var s = '<a href=\"#\">fake</a>';</script><p>real</p>","links":0,"name":"anchor markup inside a script string does not count","text":"real","title":""},{"html":"<!-- <a href=\"#\">hidden</a> --><p>shown</p>","links":0,"name":"anchor markup inside a comment does not count","text":"shown","title":""},{"html":"<title>Fish &amp; Chips &#8212; &#x2014;</title><p>body</p>","links":0,"name":"title entities are decoded (Worker regex returned them raw)","text":"body","title":"Fish & Chips — —"},{"html":"<style>a { color: red; }</style><p>body</p>","links":0,"name":"style content does not leak into text (Worker fallback leaked it)","text":"body","title":""},{"html":"<title>My Title</title>loose text","links":0,"name":"title does not leak into text","text":"loose text","title":"My Title"},{"html":"<p>before</p><script>var a = '<a href=\"#\">x</a>';","links":0,"name":"unclosed script swallows the rest of the document","text":"before","title":""},{"html":"<p>keep</p><style>.a { color: blue; }","links":0,"name":"unclosed style swallows the rest of the document","text":"keep","title":""},{"html":"<p>a b\n\tc</p>","links":0,"name":"whitespace collapses across chunks","text":"a b c","title":""},{"html":"<TITLE>Caps</TITLE><A HREF=\"#\">U</A>","links":1,"name":"uppercase tags parse like lowercase","text":"U","title":"Caps"},{"html":"<p>&lt;tag&gt; &amp; &quot;q&quot; &nbsp; end</p>","links":0,"name":"entities in text are decoded, nbsp collapses as whitespace","text":"<tag> & \"q\" end","title":""},{"html":"a<b>bold</b>c","links":0,"name":"inline markup splits text into space-joined chunks","text":"a bold c","title":""},{"html":"<title>x <a href=\"#\">y</a> z</title><p>out</p>","links":0,"name":"title is raw text: markup inside is literal and anchors do not count","text":"out","title":"x <a href=\"#\">y</a> z"},{"html":"<a title=\"2 > 1\" href=\"#\">go</a>","links":1,"name":"quoted attribute value may contain >","text":"go","title":""},{"html":"<script>1</script><style>2</style><a href=\"#\">after</a>","links":1,"name":"script and style both skipped, anchors after them count","text":"after","title":""},{"name":"unquoted attribute value ending in / is not a self-closing tag (script stays raw text)","html":"<script src=/x/>var x=\"<a href=x>fake</a>\";</script><p>real</p>","title":"","links":0,"text":"real"},{"name":"comment terminated by --!> does not swallow the rest of the document","html":"<!-- migration note --!><h1>Article title</h1><p>Article body</p>","title":"","links":0,"text":"Article title Article body"},{"name":"abruptly closed empty comment <!--> does not swallow the rest of the document","html":"<!--><p>shown</p>","title":"","links":0,"text":"shown"},{"name":"numeric character reference in the C1 range is remapped (&#128; is the euro sign)","html":"<title>Price &#128;10</title><p>body</p>","title":"Price €10","links":0,"text":"body"},{"name":"numeric character references for NUL and a surrogate become U+FFFD","html":"<p>a&#0;b&#xD800;c</p>","title":"","links":0,"text":"a�b�c"},{"name":"out-of-range numeric character reference becomes U+FFFD","html":"<p>x&#x110000;y</p>","title":"","links":0,"text":"x�y"},{"name":"apostrophe inside an unquoted attribute value does not open quote mode","html":"<a href=/it's>link</a><p>body</p>","title":"","links":1,"text":"link body"},{"name":"unknown entity names matching Object prototype properties stay literal","html":"<p>&constructor; &toString;</p>","title":"","links":0,"text":"&constructor; &toString;"},{"name":"script end tag with trailing attributes still closes the raw-text region","html":"<script>x</script foo><p>body</p>","title":"","links":0,"text":"body"}]

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.