markdown-parity-check 0.2.16 → 0.2.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -64,7 +64,7 @@ Exit code 0 means the implemented checks found nothing to reject. It does not pr
64
64
 
65
65
  Without `--selector`, the HTML content comes from the first visible `main`, `article` or `[role=main]`. If none of them exists, the page body is used and the report warns that page chrome may leak in. Two visible elements of the same kind that do not contain one another also give a warning, because only the first is compared. Front matter is kept by default and compared as content. If the HTML does not carry the same text, that alone fails the comparison. The tool also warns when the Markdown starts with a block that looks like YAML front matter, and `--front-matter strip` removes it.
66
66
 
67
- Headings, paragraphs, list items, tables, code blocks and links are compared block by block. Content marked `hidden` or `aria-hidden` is left out on both sides, and a table caption counts as a paragraph before the table. Missing and added blocks are errors. A change in text or numbers is an error too, as is a changed table or link, and a list item that shows another number or task state. A difference in order, heading level, case, punctuation, list kind or nesting level is a warning. Footnotes in the Markdown are not compared. Each one is reported as a warning, and repeated blocks are reported too.
67
+ Headings, paragraphs, list items, tables, code blocks and links are compared block by block. Content marked `hidden` or `aria-hidden` is left out on both sides, and a table caption counts as a paragraph before the table. Missing and added blocks are errors. A change in text or numbers is an error too, as is a changed table or link, and a list item that shows another number or task state. A difference in order, heading level, case, punctuation, list kind or nesting level is a warning. Footnotes in the Markdown are not compared. Each one is reported as a warning, and repeated blocks are reported too. The body of a table with a cell that has a rowspan or colspan is not compared cell by cell, and neither is the numbering of a reversed list. Each is reported as an information finding, which does not fail a check, not even with `--strict`.
68
68
 
69
69
  In URL mode the Markdown response is checked first. An HTTP error or an HTML page in place of Markdown fails the check, and nothing is compared.
70
70
 
package/dist/src/cli.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { type FetchOptions, type FetchResult } from './fetch.js';
3
- export declare const HELP = "markdown-parity-check 0.2.16\nCompares the main content of a web page's HTML and Markdown representations and reports concrete\nmissing, added and changed blocks.\n\nUsage:\n markdown-parity-check --url <https://example.com/page> [--markdown-url <url>] [options]\n markdown-parity-check --html-file <page.html> --markdown-file <page.md> [--base-url <url>] [options]\n\nModes:\n --url <url> Fetch <url> twice: with Accept: text/html and with Accept: text/markdown.\n --markdown-url <url> Fetch the Markdown from this explicit address instead (requires --url).\n --html-file <path> Offline: local HTML file (requires --markdown-file).\n --markdown-file <path> Offline: local Markdown file (requires --html-file).\n --base-url <url> Offline: base for resolving relative links on both sides.\n\nOptions:\n --html-profile generic|starlight\n HTML extraction rules (default: generic). Starlight includes inactive tab panels.\n --selector <css> CSS selector for the HTML main content (default: main, article, [role=main], then body).\n --front-matter keep|strip\n Markdown front matter. keep (default) removes nothing and warns when the document\n starts with a YAML-looking fenced block; strip removes that leading block.\n --format text|json Report format (default: text).\n --output <path> Write the report to a file instead of stdout. Refuses to overwrite an input file.\n --timeout-ms <n> Per-fetch timeout in milliseconds (default: 15000).\n --max-bytes <n> Cap on decoded response bytes per fetch (default: 5242880).\n --strict Treat warnings as rejecting findings too.\n --help, -h Show this help.\n --version, -V Show the version.\n\nExit codes:\n 0 comparison completed, no rejecting finding\n 1 comparison completed, rejecting content or delivery differences found\n 2 input, fetch, parse or report error prevented a reliable comparison\n\nOnly http(s) URLs to public addresses are fetched; loopback, private, link-local and other non-public\naddresses are refused, also behind DNS and redirects. No JavaScript is executed. Exit 0 does not prove\nsemantic equivalence.\n";
3
+ export declare const HELP = "markdown-parity-check 0.2.18\nCompares the main content of a web page's HTML and Markdown representations and reports concrete\nmissing, added and changed blocks.\n\nUsage:\n markdown-parity-check --url <https://example.com/page> [--markdown-url <url>] [options]\n markdown-parity-check --html-file <page.html> --markdown-file <page.md> [--base-url <url>] [options]\n\nModes:\n --url <url> Fetch <url> twice: with Accept: text/html and with Accept: text/markdown.\n --markdown-url <url> Fetch the Markdown from this explicit address instead (requires --url).\n --html-file <path> Offline: local HTML file (requires --markdown-file).\n --markdown-file <path> Offline: local Markdown file (requires --html-file).\n --base-url <url> Offline: base for resolving relative links on both sides.\n\nOptions:\n --html-profile generic|starlight\n HTML extraction rules (default: generic). Starlight includes inactive tab panels.\n --selector <css> CSS selector for the HTML main content (default: main, article, [role=main], then body).\n --front-matter keep|strip\n Markdown front matter. keep (default) removes nothing and warns when the document\n starts with a YAML-looking fenced block; strip removes that leading block.\n --format text|json Report format (default: text).\n --output <path> Write the report to a file instead of stdout. Refuses to overwrite an input file.\n --timeout-ms <n> Per-fetch timeout in milliseconds (default: 15000).\n --max-bytes <n> Cap on decoded response bytes per fetch (default: 5242880).\n --strict Treat warnings as rejecting findings too.\n --help, -h Show this help.\n --version, -V Show the version.\n\nExit codes:\n 0 comparison completed, no rejecting finding\n 1 comparison completed, rejecting content or delivery differences found\n 2 input, fetch, parse or report error prevented a reliable comparison\n\nOnly http(s) URLs to public addresses are fetched; loopback, private, link-local and other non-public\naddresses are refused, also behind DNS and redirects. No JavaScript is executed. Exit 0 does not prove\nsemantic equivalence.\n";
4
4
  export declare class CliError extends Error {
5
5
  }
6
6
  export interface CliArgs {
package/dist/src/cli.js CHANGED
@@ -69,12 +69,29 @@ function rawWantsJson(argv) {
69
69
  }
70
70
  return wants;
71
71
  }
72
- function positiveInt(name, raw, fallback) {
72
+ // The largest delay Node's own timer accepts (2^31 - 1 ms, about 24.8 days). A larger value is not
73
+ // rejected by Node: it becomes a roughly 1 ms timeout instead, with a TimeoutOverflowWarning, so an
74
+ // error built from the value the caller gave would misreport what is actually going to happen
75
+ // (P-N4, found by an outside review 2026-09-28).
76
+ const MAX_TIMEOUT_MS = 2147483647;
77
+ function positiveInt(name, raw, fallback, max = Number.MAX_SAFE_INTEGER) {
73
78
  if (raw === undefined)
74
79
  return fallback;
75
- if (!/^\d+$/.test(raw) || Number(raw) <= 0)
76
- throw new CliError(`${name} must be a positive integer (got "${raw}").`);
77
- return Number(raw);
80
+ // maskUrl masks the whole value in one piece before it reaches a CliError message, unlike the generic
81
+ // report redactor further down the pipeline (redactText), whose run-based URL detection splits at a raw
82
+ // space inside the value and lets a fragment such as a password through unmasked (P-N3, found by an
83
+ // outside review 2026-09-28); a CLI argument is attacker input the moment it is echoed back in an error,
84
+ // whatever option it was given for.
85
+ const shown = () => maskUrl(raw);
86
+ if (!/^\d+$/.test(raw))
87
+ throw new CliError(`${name} must be a positive integer (got "${shown()}").`);
88
+ const n = Number(raw);
89
+ // A long enough run of digits overflows the IEEE 754 double to Infinity, which the old "> 0" check let
90
+ // through unrejected; Number.isFinite closes that, and max rejects a value this option cannot actually
91
+ // honor before it reaches the code that would silently reinterpret it (P-N4).
92
+ if (!Number.isFinite(n) || n <= 0 || n > max)
93
+ throw new CliError(`${name} must be a positive integer, at most ${max} (got "${shown()}").`);
94
+ return n;
78
95
  }
79
96
  export function parseCliArgs(argv) {
80
97
  let parsed;
@@ -126,7 +143,7 @@ export function parseCliArgs(argv) {
126
143
  frontMatter,
127
144
  format,
128
145
  output: v.output,
129
- timeoutMs: positiveInt('--timeout-ms', v['timeout-ms'], 15000),
146
+ timeoutMs: positiveInt('--timeout-ms', v['timeout-ms'], 15000, MAX_TIMEOUT_MS),
130
147
  maxBytes: positiveInt('--max-bytes', v['max-bytes'], 5 * 1024 * 1024),
131
148
  strict: v.strict ?? false,
132
149
  help: v.help ?? false,
@@ -307,18 +324,29 @@ export async function main(argv, io = { stdout: (s) => process.stdout.write(s),
307
324
  }
308
325
  catch (err) {
309
326
  let message;
327
+ let value;
310
328
  if (err instanceof FetchError)
311
329
  message = `Fetch failed (${err.kind}) for ${err.url}: ${err.message}`;
312
- else if (err instanceof CliError || err instanceof RunError)
330
+ else if (err instanceof CliError)
313
331
  message = err.message;
332
+ else if (err instanceof RunError) {
333
+ message = err.message;
334
+ value = err.value;
335
+ }
314
336
  else
315
337
  message = `Unexpected error: ${err.stack ?? String(err)}`;
316
- report = errorReport(options, html?.meta ?? null, markdown?.meta ?? null, message);
338
+ report = errorReport(options, html?.meta ?? null, markdown?.meta ?? null, message, value);
317
339
  try {
318
340
  emit(report, args, io);
319
341
  }
320
342
  catch (e2) {
321
- io.stderr(`Error: ${e2.message}\n`);
343
+ // The report itself could not be written (P-N5, found by an outside review 2026-09-28): up to here
344
+ // this fell through to a plain stderr line only, even under --format json, unlike every other error
345
+ // path in this function, which puts a JSON report on stdout too when JSON was asked for.
346
+ const writeMessage = e2.message;
347
+ if (args.format === 'json')
348
+ io.stdout(renderJson(errorReport(options, html?.meta ?? null, markdown?.meta ?? null, writeMessage)));
349
+ io.stderr(`Error: ${writeMessage}\n`);
322
350
  }
323
351
  io.stderr(`Error: ${message}\n`);
324
352
  return 2;
@@ -327,7 +355,12 @@ export async function main(argv, io = { stdout: (s) => process.stdout.write(s),
327
355
  emit(report, args, io);
328
356
  }
329
357
  catch (err) {
330
- io.stderr(`Error: ${err.message}\n`);
358
+ // Same P-N5 fallback as the error path above: a write failure got only a plain stderr line before,
359
+ // even under --format json.
360
+ const writeMessage = err.message;
361
+ if (args.format === 'json')
362
+ io.stdout(renderJson(errorReport(options, html?.meta ?? null, markdown?.meta ?? null, writeMessage)));
363
+ io.stderr(`Error: ${writeMessage}\n`);
331
364
  return 2;
332
365
  }
333
366
  return report.summary.exitCode;
@@ -266,7 +266,10 @@ function compareListItems(out, h, m) {
266
266
  function compareTables(out, h, m) {
267
267
  // A spanned table already carries its one EXTRACTION_TABLE_SPAN_NOT_COMPARED issue from extraction; the cell
268
268
  // positions html.ts still filled in are not reliable, so no cell-by-cell finding is added here (0.2.16).
269
- if (h.spanned)
269
+ // m.spanned matters just as much: a table that is spanned only inside a raw HTML block on the Markdown
270
+ // side (N-P-raw-html, found by an outside review 2026-09-28) carried unreliable cell positions there, and
271
+ // checking h.spanned alone still ran the cell-by-cell comparison below against them.
272
+ if (h.spanned || m.spanned)
270
273
  return;
271
274
  const hc = h.cells ?? [];
272
275
  const mc = m.cells ?? [];
@@ -11,6 +11,12 @@ export interface HtmlExtractOptions {
11
11
  maxDepth?: number;
12
12
  }
13
13
  export declare class HtmlExtractError extends Error {
14
+ /** The user-supplied value the message names (here, --selector), capped the way worker.js's own cut()
15
+ * caps a reflected value: in its own field, not only interpolated into the sentence, and bounded so an
16
+ * arbitrarily long selector cannot make the error text arbitrarily long (V10-P3-01, found by an outside
17
+ * review 2026-09-28). Report rendering still masks every string, value included, through redactText. */
18
+ value?: string;
19
+ constructor(message: string, value?: string);
14
20
  }
15
21
  /** Default nesting limit for both extractors. The extraction walks the tree recursively, and a document
16
22
  * nested a few thousand levels deep exhausts the call stack (measured 2026-09-11: 5 000 nested div
package/dist/src/html.js CHANGED
@@ -5,6 +5,22 @@ import { selectAll, selectOne } from 'css-select';
5
5
  import { Element, Text } from 'domhandler';
6
6
  import { extractNumbers, looseNormalize, normalizeCode, resolveHref, strictNormalize } from './normalize.js';
7
7
  export class HtmlExtractError extends Error {
8
+ /** The user-supplied value the message names (here, --selector), capped the way worker.js's own cut()
9
+ * caps a reflected value: in its own field, not only interpolated into the sentence, and bounded so an
10
+ * arbitrarily long selector cannot make the error text arbitrarily long (V10-P3-01, found by an outside
11
+ * review 2026-09-28). Report rendering still masks every string, value included, through redactText. */
12
+ value;
13
+ constructor(message, value) {
14
+ super(message);
15
+ if (value !== undefined)
16
+ this.value = capValue(value);
17
+ }
18
+ }
19
+ /** Caps a value that a message reflects back to the caller, the same length worker.js's own cut() uses, and
20
+ * drops a trailing lone high surrogate a plain slice can leave behind. */
21
+ function capValue(s, n = 120) {
22
+ const cut = s.slice(0, n);
23
+ return /[\uD800-\uDBFF]$/.test(cut) ? cut.slice(0, -1) : cut;
8
24
  }
9
25
  /** Default nesting limit for both extractors. The extraction walks the tree recursively, and a document
10
26
  * nested a few thousand levels deep exhausts the call stack (measured 2026-09-11: 5 000 nested div
@@ -346,7 +362,11 @@ function taskState(li) {
346
362
  const stack = [...li.children].reverse();
347
363
  while (stack.length > 0) {
348
364
  const node = stack.pop();
349
- if (!(node instanceof Element) || node.name === 'ul' || node.name === 'ol')
365
+ // A <template> element's content is inert: the browser never renders it as part of the document, the
366
+ // same reason hiddenInPage above treats it like a hidden ancestor for the main extraction. taskState had
367
+ // no matching check, so a checkbox sitting in a <template> answered for a later, real checkbox in the
368
+ // same item (found by an outside review 2026-09-28).
369
+ if (!(node instanceof Element) || node.name === 'ul' || node.name === 'ol' || node.name === 'template')
350
370
  continue;
351
371
  if (hiddenAttr(node))
352
372
  continue;
@@ -399,6 +419,12 @@ function starlightCode(pre) {
399
419
  const code = meaningful.length === 1 ? meaningful[0] : null;
400
420
  if (!(code instanceof Element) || code.name !== 'code')
401
421
  return visibleCode(pre.children);
422
+ // The specialized shape below reads code.children directly and never passes through visibleCode, so a
423
+ // hidden or aria-hidden <code> wrapper (the whole block, not one .ec-line inside it) was never checked and
424
+ // its lines were exported as if visible (found by an outside review 2026-09-28). A hidden wrapper has no
425
+ // visible code at all, the same outcome visibleCode itself gives a hidden element anywhere else.
426
+ if (hiddenAttr(code))
427
+ return '';
402
428
  const lines = code.children.filter((node) => !(node instanceof Text && !node.data.trim()));
403
429
  if (lines.length === 0 || !lines.every((node) => node instanceof Element && node.name === 'div' && hasClass(node, 'ec-line')))
404
430
  return visibleCode(pre.children);
@@ -521,14 +547,20 @@ function handleStarlightTabs(ctx, component) {
521
547
  * absent, empty or "1" value is the default and is not a span. An unparseable value is treated as a span too,
522
548
  * because a plain grid reading cannot tell what it means either. */
523
549
  function hasSpan(el) {
524
- const spans = (attr) => {
550
+ // rowspan="0" is a distinct HTML value: the cell extends through every remaining row of its row group, so
551
+ // it moves a following row's cell into a different column just as rowspan="2" does, but it was read as
552
+ // n > 1 like an ordinary count and 0 failed that test (found by an outside review 2026-09-28). colspan has
553
+ // no such magic zero value in the HTML parsing algorithm, so its own zero stays "not a span".
554
+ const spans = (attr, zeroIsSpan) => {
525
555
  const v = el.attribs[attr];
526
556
  if (v === undefined)
527
557
  return false;
528
558
  const n = Number.parseInt(v, 10);
529
- return !Number.isFinite(n) || n > 1;
559
+ if (!Number.isFinite(n))
560
+ return true;
561
+ return n > 1 || (zeroIsSpan && n === 0);
530
562
  };
531
- return spans('rowspan') || spans('colspan');
563
+ return spans('rowspan', true) || spans('colspan', false);
532
564
  }
533
565
  function handleTable(ctx, table) {
534
566
  // The caption is content: a paragraph before the table, the way a Markdown table's title has to be written. Up to
@@ -604,12 +636,12 @@ function pickRoot(doc, selector, notes, issues) {
604
636
  matches = selectAll(selector, doc.children).filter((n) => n instanceof Element);
605
637
  }
606
638
  catch (err) {
607
- throw new HtmlExtractError(`Invalid selector "${selector}": ${err.message}`);
639
+ throw new HtmlExtractError(`Invalid selector: ${err.message}`, selector);
608
640
  }
609
641
  if (matches.length === 0)
610
- throw new HtmlExtractError(`Selector "${selector}" matched no element.`);
642
+ throw new HtmlExtractError('Selector matched no element.', selector);
611
643
  if (matches.length > 1)
612
- notes.push(`Selector "${selector}" matched ${matches.length} elements; the first in document order was used.`);
644
+ notes.push(`Selector "${capValue(selector)}" matched ${matches.length} elements; the first in document order was used.`);
613
645
  return { root: matches[0], strategy: `selector:${selector}`, confidence: 'high' };
614
646
  }
615
647
  // A candidate the page hides is not its main content. Up to 0.2.12 the first candidate was taken as it was, so a
@@ -339,6 +339,16 @@ function handleRawHtml(ctx, value, line) {
339
339
  const absolute = line !== undefined && inner !== undefined ? line + inner - 1 : line;
340
340
  ctx.blocks.push({ ...b, location: { line: absolute, blockIndex: ctx.blocks.length } });
341
341
  }
342
+ // The nested extraction's own structural "not compared" issues (a spanned table, a reversed list) were
343
+ // read off parsed.blocks only up to here; parsed.issues was silently dropped, so a page whose span or
344
+ // reversed numbering lived inside a raw HTML block in the Markdown showed only the generic
345
+ // MARKDOWN_RAW_HTML_PARSED note about readers that do not render HTML, with no disclosure that the span
346
+ // or the numbering itself was not reliably compared (N-P-raw-html, found by an outside review
347
+ // 2026-09-28). The line offset matches the block loop just above.
348
+ for (const i of parsed?.issues ?? []) {
349
+ const absolute = line !== undefined && i.line !== undefined ? line + i.line - 1 : line;
350
+ ctx.issues.push({ ...i, line: absolute });
351
+ }
342
352
  ctx.issues.push({ code: 'MARKDOWN_RAW_HTML_PARSED', severity: 'info', message: `A raw HTML block in the Markdown was parsed as HTML (${blocks.length} block(s)); Markdown readers that do not render HTML will not see it.`, line, excerpt: excerpt(textOnly) });
343
353
  }
344
354
  else if (textOnly !== '') {
@@ -10,8 +10,8 @@ export declare function stripControlChars(text: string): string;
10
10
  export declare function extractNumbers(text: string): string[];
11
11
  /** Report excerpt: URLs inside the text are masked BEFORE truncation, so a cut query value cannot leak. */
12
12
  export declare function excerpt(text: string, max?: number): string;
13
- /** Masks a "scheme://(name):secret@" userinfo, leaving the scheme and an unmasked "***@" behind so the rest of
14
- * the URL (host, path, query, fragment) reaches the ordinary run-based masking below as one unbroken run. */
13
+ /** Masks every "scheme://(name):secret@" userinfo, leaving the scheme and an unmasked "***@" behind so the rest
14
+ * of the URL (host, path, query, fragment) reaches the ordinary run-based masking below as one unbroken run. */
15
15
  export declare function maskParenUserinfo(text: string): string;
16
16
  /**
17
17
  * Whether position at of a source text lies in a part of a URL that maskHref hides: user information, a query
@@ -272,27 +272,78 @@ const HIDDEN_SCAN = 4096;
272
272
  // A userinfo wrapped in parentheses right after "scheme://", such as scheme://(name):secret@host, is not a
273
273
  // URL-like run under RUN above, because "(" and ")" split runs there: "scheme://", the parenthesized name and
274
274
  // the rest starting at the colon become three separate runs, and none of them alone looks like a URL with user
275
- // information (found by an outside review 2026-09-28). This pattern is narrow and every quantifier is bounded on
276
- // purpose, so it stays linear by itself and is checked before the general run-splitting scan, not folded into it.
277
- const PAREN_USERINFO = /\b([a-z][a-z0-9+.-]{0,15}):\/\/\(([^()\s]{0,256})\):([^@\s<>"'()]{0,1024})@/giu;
278
- /** Masks a "scheme://(name):secret@" userinfo, leaving the scheme and an unmasked "***@" behind so the rest of
279
- * the URL (host, path, query, fragment) reaches the ordinary run-based masking below as one unbroken run. */
275
+ // information (found by an outside review 2026-09-28).
276
+ //
277
+ // Fail-closed (found by an outside review 2026-09-28): up to here the whole shape (scheme, name, secret and the
278
+ // closing "@") was one regex whose name and secret each carried a fixed quantifier cap (256 and 1024 characters).
279
+ // A name or secret one character longer than its own cap made the regex fail to match at that position at all, so
280
+ // the userinfo reached a report completely unmasked instead of masked, the opposite of what a redaction function
281
+ // should do when it cannot tell how long something is. nextParenUserinfo below finds the fixed "scheme://(" start
282
+ // with a small bounded regex (the scheme name itself is capped at 32 characters, which no real scheme name
283
+ // approaches) and then reads the name and the secret by hand with indexOf, inside PAREN_USERINFO_SCAN characters
284
+ // of that point: a name or secret near the old 256/1024 limits, or well past them, is found and masked all the
285
+ // same, as long as its closing ")" or its "@" sits within that window. When the secret's end cannot be found that
286
+ // way either (no "@" and no other stopping character before the window runs out), the match is still made and
287
+ // masked through the end of the window, because not knowing where a credential ends is a reason to mask more of
288
+ // it, not less. This keeps the scan linear in the length of the text: each "(" is looked at once, and the work
289
+ // done for it is bounded by PAREN_USERINFO_SCAN regardless of how long the rest of the text is, the same trade-off
290
+ // HIDDEN_SCAN below already makes for the same class of problem.
291
+ const PAREN_USERINFO_START = /\b([a-z][a-z0-9+.-]{0,31}):\/\/\(/giu;
292
+ const PAREN_USERINFO_SCAN = HIDDEN_SCAN;
293
+ /** Finds the next "scheme://(name):secret@" match at or after `from`. See the fail-closed rationale above. */
294
+ function nextParenUserinfo(text, from) {
295
+ const re = new RegExp(PAREN_USERINFO_START.source, PAREN_USERINFO_START.flags);
296
+ re.lastIndex = from;
297
+ for (let m = re.exec(text); m !== null; m = re.exec(text)) {
298
+ const nameStart = m.index + m[0].length;
299
+ const nameWindowEnd = Math.min(text.length, nameStart + PAREN_USERINFO_SCAN);
300
+ const nameWindow = text.slice(nameStart, nameWindowEnd);
301
+ const close = nameWindow.indexOf(')');
302
+ const stop = nameWindow.search(/[\s(]/);
303
+ if (close < 0 || (stop >= 0 && stop < close) || nameWindow[close + 1] !== ':') {
304
+ // No well-formed "):" landmark within the window: this "(" is not the shape we mask, so it is left as it is
305
+ // and the search resumes right after it, not from the start again.
306
+ re.lastIndex = nameStart;
307
+ continue;
308
+ }
309
+ const secretStart = nameStart + close + 2;
310
+ const secretWindowEnd = Math.min(text.length, secretStart + PAREN_USERINFO_SCAN);
311
+ const secretWindow = text.slice(secretStart, secretWindowEnd);
312
+ // Once the "):" landmark is found, this is the dangerous shape, so the secret is always masked from here on,
313
+ // through an "@", another character that could not be part of it, or the scan bound itself (fail-closed).
314
+ const stopChar = secretWindow.search(/[@\s()<>"']/);
315
+ const atStop = stopChar >= 0 && secretWindow[stopChar] === '@';
316
+ const secretEnd = stopChar < 0 ? secretWindowEnd : secretStart + stopChar;
317
+ return { start: m.index, scheme: m[1], nameStart, secretStart, secretEnd, end: atStop ? secretEnd + 1 : secretEnd };
318
+ }
319
+ return null;
320
+ }
321
+ /** Masks every "scheme://(name):secret@" userinfo, leaving the scheme and an unmasked "***@" behind so the rest
322
+ * of the URL (host, path, query, fragment) reaches the ordinary run-based masking below as one unbroken run. */
280
323
  export function maskParenUserinfo(text) {
281
- return text.replace(PAREN_USERINFO, (_m, scheme) => `${scheme}://***@`);
324
+ let out = '';
325
+ let pos = 0;
326
+ for (let m = nextParenUserinfo(text, pos); m !== null; m = nextParenUserinfo(text, pos)) {
327
+ out += text.slice(pos, m.start) + `${m.scheme}://***@`;
328
+ pos = m.end;
329
+ }
330
+ return out + text.slice(pos);
282
331
  }
283
- /** Whether position `at` falls inside the parenthesized name or the secret of a PAREN_USERINFO match, the same
284
- * shape maskParenUserinfo hides. The search window is the same HIDDEN_SCAN bound insideHiddenUrlPart itself uses,
285
- * so a link deep inside a large document does not rescan the whole source. */
332
+ /** Whether position `at` falls inside the parenthesized name or the secret of a nextParenUserinfo match, the same
333
+ * span maskParenUserinfo hides. The search starts and stops within the same HIDDEN_SCAN window
334
+ * insideHiddenUrlPart itself uses, so a link deep inside a large document does not rescan the whole source. */
286
335
  function insideParenUserinfo(text, at) {
287
336
  const from = Math.max(0, at - HIDDEN_SCAN);
288
337
  const to = Math.min(text.length, at + HIDDEN_SCAN);
289
- const window = text.slice(from, to);
290
- const re = new RegExp(PAREN_USERINFO.source, PAREN_USERINFO.flags);
291
- for (let m = re.exec(window); m !== null; m = re.exec(window)) {
292
- const hiddenStart = from + m.index + m[1].length + 3; // scheme + "://", at the "("
293
- const hiddenEnd = from + m.index + m[0].length - 1; // at the "@"
294
- if (at >= hiddenStart && at < hiddenEnd)
338
+ let pos = from;
339
+ while (pos < to) {
340
+ const m = nextParenUserinfo(text, pos);
341
+ if (!m || m.start >= to)
342
+ return false;
343
+ const hiddenStart = m.nameStart - 1; // the "("
344
+ if (at >= hiddenStart && at < m.secretEnd)
295
345
  return true;
346
+ pos = m.end;
296
347
  }
297
348
  return false;
298
349
  }
@@ -354,7 +405,12 @@ export function redactText(text) {
354
405
  * and the fragment. Nothing else moves, and nothing is normalized, so every other number stays as it was.
355
406
  */
356
407
  export function hideUrlSecrets(text) {
357
- return rewriteUrlRuns(text, withoutUrlSecrets);
408
+ // maskParenUserinfo runs first, the same order redactText uses, so a numeric password in the
409
+ // parenthesized-userinfo shape cannot reach extractNumbers as plain text (P-N1, found by an outside
410
+ // review 2026-09-28): up to here only redactText applied it, so visibleNumbers below still read a
411
+ // number straight out of an unmasked "(name):secret@" that the general run-based scan cannot see as
412
+ // one run (see the comment on PAREN_USERINFO_START above).
413
+ return rewriteUrlRuns(maskParenUserinfo(text), withoutUrlSecrets);
358
414
  }
359
415
  /**
360
416
  * The numeric tokens a report may show. extractNumbers reads the whole text, so a numeric query value, such as
@@ -54,7 +54,9 @@ export function renderText(input) {
54
54
  const s = report.summary;
55
55
  out.push(`${TOOL_NAME} ${report.toolVersion} (${report.mode} mode${s.strict ? ', strict' : ''})`);
56
56
  if (s.result === 'error') {
57
- out.push(`Result: ERROR. ${s.error ?? 'The comparison could not be completed.'}`);
57
+ // errorValue (V10-P3-01) is the specific input value the message names, already capped where it was
58
+ // built; shown as its own labelled part rather than folded back into the sentence.
59
+ out.push(`Result: ERROR. ${s.error ?? 'The comparison could not be completed.'}${s.errorValue !== undefined ? ` (value: "${s.errorValue}")` : ''}`);
58
60
  }
59
61
  else {
60
62
  out.push(`Result: ${s.result.toUpperCase()} (${s.errors} error(s), ${s.warnings} warning(s), ${s.infos} info)`);
package/dist/src/run.d.ts CHANGED
@@ -69,16 +69,22 @@ export interface Report {
69
69
  exitCode: 0 | 1 | 2;
70
70
  /** Present when the comparison could not be completed reliably. */
71
71
  error?: string;
72
+ /** The specific input value error names, capped and reported in its own field rather than only inside
73
+ * the message sentence (V10-P3-01, the same split worker.js's own diagnostics already use). */
74
+ errorValue?: string;
72
75
  };
73
76
  findings: Finding[];
74
77
  limitations: string[];
75
78
  }
76
79
  export declare class RunError extends Error {
77
- constructor(message: string);
80
+ /** Carries HtmlExtractError's own capped, separately-fielded reflected value (V10-P3-01) through to the
81
+ * report, instead of only the sentence that already names it. */
82
+ value?: string;
83
+ constructor(message: string, value?: string);
78
84
  }
79
85
  export declare const LIMITATIONS: string[];
80
86
  /** Findings about how the Markdown was delivered, produced by the URL mode before extraction. */
81
87
  export declare function deliveryFindings(md: SourceMeta, body: string): Finding[];
82
88
  export declare function run(html: SourceInput, markdown: SourceInput, options: RunOptions): Report;
83
- export declare function errorReport(options: RunOptions, html: SourceMeta | null, markdown: SourceMeta | null, message: string): Report;
89
+ export declare function errorReport(options: RunOptions, html: SourceMeta | null, markdown: SourceMeta | null, message: string, value?: string): Report;
84
90
  export { maskUrl };
package/dist/src/run.js CHANGED
@@ -9,16 +9,22 @@ import { TOOL_VERSION } from './version.js';
9
9
  export { MAX_NESTING_DEPTH };
10
10
  /** Parser stack exhaustion on hostile nesting is reported as a comparison error, never as a crash. */
11
11
  function extractionError(side, err) {
12
- if (err instanceof HtmlExtractError || err instanceof MarkdownExtractError)
12
+ if (err instanceof HtmlExtractError)
13
+ return new RunError(err.message, err.value);
14
+ if (err instanceof MarkdownExtractError)
13
15
  return new RunError(err.message);
14
16
  if (err instanceof RangeError)
15
17
  return new RunError(`The ${side} could not be parsed within the call stack (${err.message}); it is nested too deeply to compare.`);
16
18
  return null;
17
19
  }
18
20
  export class RunError extends Error {
19
- constructor(message) {
21
+ /** Carries HtmlExtractError's own capped, separately-fielded reflected value (V10-P3-01) through to the
22
+ * report, instead of only the sentence that already names it. */
23
+ value;
24
+ constructor(message, value) {
20
25
  super(message);
21
26
  this.name = 'RunError';
27
+ this.value = value;
22
28
  }
23
29
  }
24
30
  export const LIMITATIONS = [
@@ -129,10 +135,12 @@ export function run(html, markdown, options) {
129
135
  report.summary = { result: failing ? 'fail' : 'pass', strict: options.strict, ...c, coverage: result.coverage, exitCode: failing ? 1 : 0 };
130
136
  return report;
131
137
  }
132
- export function errorReport(options, html, markdown, message) {
138
+ export function errorReport(options, html, markdown, message, value) {
133
139
  const empty = { kind: options.mode === 'url' ? 'url' : 'file', bytes: 0 };
134
140
  const r = baseReport(options, html ?? empty, markdown ?? empty);
135
141
  r.summary.error = message;
142
+ if (value !== undefined)
143
+ r.summary.errorValue = value;
136
144
  return r;
137
145
  }
138
146
  export { maskUrl };
@@ -1,2 +1,2 @@
1
1
  export declare const TOOL_NAME = "markdown-parity-check";
2
- export declare const TOOL_VERSION = "0.2.16";
2
+ export declare const TOOL_VERSION = "0.2.18";
@@ -2,4 +2,4 @@
2
2
  // Cloudflare Worker as well as under Node.js. test/version.test.ts fails the build when these differ
3
3
  // from package.json, which stays the version the release workflow publishes.
4
4
  export const TOOL_NAME = 'markdown-parity-check';
5
- export const TOOL_VERSION = '0.2.16';
5
+ export const TOOL_VERSION = '0.2.18';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-parity-check",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
4
4
  "description": "Compares the main content of a web page's HTML and Markdown representations and reports concrete differences.",
5
5
  "keywords": [
6
6
  "markdown",