markdown-parity-check 0.2.41 → 0.2.42

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
@@ -78,10 +78,10 @@ A value that is outside these ranges, or that is not a plain run of digits, stop
78
78
 
79
79
  ### Example output
80
80
 
81
- This is the text report for the matching fixture pair in this repository, run with version 0.2.41 on 2026-11-22. The exact command is in the Development section below. The text report ends with a list of limitations, which is omitted here:
81
+ This is the text report for the matching fixture pair in this repository, run with version 0.2.42 on 2026-11-22. The exact command is in the Development section below. The text report ends with a list of limitations, which is omitted here:
82
82
 
83
83
  ```text
84
- markdown-parity-check 0.2.41 (offline mode)
84
+ markdown-parity-check 0.2.42 (offline mode)
85
85
  Result: PASS (0 error(s), 0 warning(s), 1 info)
86
86
 
87
87
  HTML: test/fixtures/same/page.html (file, 1,017 bytes, base https://example.com/page)
@@ -151,7 +151,7 @@ The choice follows the type of the response, not the request. Any other response
151
151
 
152
152
  JavaScript is not executed. Content that a page builds in the browser is compared as the server sent it. Block matching is heuristic, so some layouts need an explicit selector. Reports mask URL query values and fragments and remove the user name and password of an address with a scheme, such as `https://user:password@host/`. Excerpts may still contain private page content. Review a report before you share it.
153
153
 
154
- The masking is a display safeguard that does not hide ordinary text, so it has limits, and this paragraph is the full list. It removes the user name and password even when a tab, a line break or a space sits inside the user information, provided that the user information holds a colon, as in `user:password`. A user name alone, with no colon, is masked when a tab, a vertical tab or a form feed sits inside it, and is shown when a space, a no-break space, a line feed or a carriage return does, because a line break or a space between an address and an e-mail address is ordinary text. On a bare host name without a scheme, a query or a fragment is masked only when it holds an equals sign, so an anchor such as `example.com/docs/guide#step-3` and a path segment are shown. Not masked: a bracketed IPv6 host, a host with a trailing dot, a name with no dot other than `localhost` and an scp-style `git@host:path`. A scheme-less `user:password@host.example/path` is masked as `user:***@host.example/path`, and so is the e-mail link that the Markdown parser reads out of it, when a path, a query that holds a value or a fragment that holds an equals sign follows the host name. Without one, as in `user:password@host.example` or `Contact:jane@example.com`, it is shown, because text alone cannot tell a user name from a label. The scheme-less form is also shown when its host name holds a letter outside ASCII, or when its colon or at sign is written as a character reference or a fullwidth character. An address after `mailto:`, `xmpp:`, `sip:`, `sips:`, `acct:` or `im:` is shown as written. A link target that holds an `@` is shown as its scheme and `//***`, as `gopher:***` for a non-special scheme such as `gopher:`, or as `***`, when a URL parser and a person could read its user information at different places. A special scheme such as `https:` with fewer than two slashes or backslashes after its colon is one such case, as in `https:/user:password@host.example/x`. An authority with a backslash, a `?` or a `#` before its last `@` and before any `/` is another, as in `https://CORP\erik:password@host.example/x`, and `https://example.com?e=a@b.com` reads the same way. An authority that the URL parser refuses, as with the port in `https://user:pa/ss?password@host.example`, and a `file:` URL are masked as well. So are a scheme that the parser refuses, as in `user_name:password@host.example`, and a non-special scheme such as `gopher:` whose text before the `@` holds a colon. Each of these shapes is masked after a leading Unicode space or a NUL character too. A target of these shapes is shown this way also when it holds no user information, such as `file:///home/a@b.txt`. Not masked: a password that starts with `/` or with digits and `/`, as in `https://user:/password@host.example`, which the URL parser reads as a host and a path and which text alone cannot tell from a path that holds an `@`, such as `https://localhost:8080/team@example.com`, and a relative path such as `/user:password@host.example`, which both readers take as a path. A plain space or a no-break space right after the colon of the user information, and a password of digits only that is followed by white space, are read as text and shown. The masking changes what a report shows and never what is compared, and a number difference inside a masked part still gives the number finding, with the values left out. In both formats U+200E, U+200F, U+061C, U+2028, U+2029 and the tag characters are removed from report text. The text report shows a line feed or a carriage return inside a string from a page or an argument as `\n` or `\r`.
154
+ The masking is a display safeguard that does not hide ordinary text, so it has limits, and this paragraph is the full list. It removes the user name and password even when a tab, a line break or a space sits inside the user information, provided that the user information holds a colon, as in `user:password`. A user name alone, with no colon, is masked when a tab, a vertical tab or a form feed sits inside it, and is shown when a space, a no-break space, a line feed or a carriage return does, because a line break or a space between an address and an e-mail address is ordinary text. On a bare host name without a scheme, a query or a fragment is masked only when it holds an equals sign, so an anchor such as `example.com/docs/guide#step-3` and a path segment are shown. Not masked: a bracketed IPv6 host, a host with a trailing dot, a name with no dot other than `localhost` and an scp-style `git@host:path`. A scheme-less `user:password@host.example/path` is masked as `user:***@host.example/path`, and so is the e-mail link that the Markdown parser reads out of it, when a path, a query that holds a value or a fragment that holds an equals sign follows the host name. Without one, as in `user:password@host.example` or `Contact:jane@example.com`, it is shown, because text alone cannot tell a user name from a label. The scheme-less form is also shown when its host name holds a letter outside ASCII, or when its colon or at sign is written as a character reference or a fullwidth character. An address after `mailto:`, `xmpp:`, `sip:`, `sips:`, `acct:` or `im:` is shown as written. A link target that holds an `@` is shown as its scheme and `//***`, as `gopher:***` for a non-special scheme such as `gopher:`, or as `***`, when a URL parser and a person could read its user information at different places. A special scheme such as `https:` with fewer than two slashes or backslashes after its colon is one such case, as in `https:/user:password@host.example/x`. An authority with a backslash, a `?` or a `#` before its last `@` and before any `/` is another, as in `https://CORP\erik:password@host.example/x`, and `https://example.com?e=a@b.com` reads the same way. An authority that the URL parser refuses, as with the port in `https://user:pa/ss?password@host.example`, and a `file:` URL are masked as well. So are a scheme that the parser refuses, as in `user_name:password@host.example`, and a non-special scheme such as `gopher:` whose text before the `@` holds a colon. So is a target without a scheme word before its colon that holds a colon and no `/` before its last `@`, as in `CORP\erik:password@host.example/x`, `:password@host.example/x` or `erik@:password@host.example/x`, which is shown as `***`. Each of these shapes is masked after a leading Unicode space or a NUL character too. A base address of these shapes, given as `--base-url` or written in a `<base href>`, as in `https://CORP\erik:password@host.example/dir/`, is shown as its scheme and `//***/`, and a relative link resolved against it is shown as written, not as resolved. In the URL mode, a followed redirect whose `Location` has one of these shapes makes the final address show as its scheme and `//***/`, in the report and in a fetch error, and the links resolved against it are shown as written. So does a `--url` of these shapes, as in `http://host.example:8080\erik:password@other.example/p`, which the URL parser reads as a host, a port and a path. A target of these shapes is shown this way also when it holds no user information, such as `file:///home/a@b.txt`. Not masked: a password that starts with `/` or with digits and `/`, as in `https://user:/password@host.example`, which the URL parser reads as a host and a path and which text alone cannot tell from a path that holds an `@`, such as `https://localhost:8080/team@example.com`, and a relative path such as `/user:password@host.example`, which both readers take as a path. A plain space or a no-break space right after the colon of the user information, and a password of digits only that is followed by white space, are read as text and shown. The masking changes what a report shows and never what is compared, and a number difference inside a masked part still gives the number finding, with the values left out. In both formats U+200E, U+200F, U+061C, U+2028, U+2029 and the tag characters are removed from report text. The text report shows a line feed or a carriage return inside a string from a page or an argument as `\n` or `\r`.
155
155
 
156
156
  A link target longer than 8192 characters stops the run with exit code 2 and an error that names the limit and does not repeat the target. The comparison handles a target once for every link, block or reference that touches it, so the time grew with the length of the target times that count. The limit applies to the target as the page or the Markdown wrote it, before any resolution.
157
157
 
@@ -272,12 +272,12 @@ Only after that check does it create the GitHub release with the verified tarbal
272
272
  GitHub Actions publishes every version from 0.1.2 on with npm trusted publishing, and each one carries a provenance attestation. To check one, install it in an empty directory and ask npm to verify the signatures. Replace the version with the one you want to check.
273
273
 
274
274
  ```sh
275
- mkdir verify-mpc && cd verify-mpc && npm init -y && npm install markdown-parity-check@0.2.41 --ignore-scripts && npm audit signatures
275
+ mkdir verify-mpc && cd verify-mpc && npm init -y && npm install markdown-parity-check@0.2.42 --ignore-scripts && npm audit signatures
276
276
  ```
277
277
 
278
278
  `npm audit signatures` checks the registry signature and the provenance attestation of each installed package that has one. The attestation of this package names three things to compare with what you expect: the repository `github.com/erekola/markdown-parity-check`, the workflow file `.github/workflows/release.yml` and the commit that produced the tarball. The npm version page shows them under Provenance.
279
279
 
280
- Tag `v0.2.41` must point at that same commit, and `gh api repos/erekola/markdown-parity-check/commits/v0.2.41 --jq .sha` prints it. A mismatch is a reason not to use that version. Provenance proves which workflow built a release and from which commit. It does not prove that the code is safe, so reading the source and the dependencies stays your job.
280
+ Tag `v0.2.42` must point at that same commit, and `gh api repos/erekola/markdown-parity-check/commits/v0.2.42 --jq .sha` prints it. A mismatch is a reason not to use that version. Provenance proves which workflow built a release and from which commit. It does not prove that the code is safe, so reading the source and the dependencies stays your job.
281
281
 
282
282
  ## Security
283
283
 
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.41\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> Timeout in milliseconds for each fetch and for the parse-and-compare step\n (default: 15000). When it runs out the exit code is 2.\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.42\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> Timeout in milliseconds for each fetch and for the parse-and-compare step\n (default: 15000). When it runs out the exit code is 2.\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
@@ -9,7 +9,7 @@ import { fetchUrl, FetchError, validateUrl } from './fetch.js';
9
9
  import { renderJson, renderText } from './report.js';
10
10
  import { runWithDeadline } from './deadline.js';
11
11
  import { errorReport, RunError } from './run.js';
12
- import { maskUrl, redactText } from './normalize.js';
12
+ import { maskUrl, movedUserinfoMask, redactText } from './normalize.js';
13
13
  import { TOOL_NAME, TOOL_VERSION } from './version.js';
14
14
  export const HELP = `${TOOL_NAME} ${TOOL_VERSION}
15
15
  Compares the main content of a web page's HTML and Markdown representations and reports concrete
@@ -350,14 +350,18 @@ function readFileInput(file, base) {
350
350
  }
351
351
  if (body.charCodeAt(0) === 0xfeff)
352
352
  body = body.slice(1);
353
- return { meta: { kind: 'file', file, bytes: Buffer.byteLength(body, 'utf8'), baseUrl: base ? maskUrl(base) : null }, body, base };
353
+ // movedUserinfoMask first: maskUrl showed https://CORP\erik:secret@host/dir/ as https://corp/erik:secret@host/dir/ (n6).
354
+ return { meta: { kind: 'file', file, bytes: Buffer.byteLength(body, 'utf8'), baseUrl: base ? movedUserinfoMask(base) ?? maskUrl(base) : null }, body, base };
354
355
  }
355
356
  async function fetchInput(url, accept, args, fetchFn) {
356
357
  const res = await fetchFn(url, { accept, timeoutMs: args.timeoutMs, maxBytes: args.maxBytes });
358
+ // shownFinalUrl stands in for the final address when a redirect hid user information in it (fetchUrl).
359
+ const shownFinal = res.shownFinalUrl ?? maskUrl(res.finalUrl);
357
360
  return {
358
- meta: { kind: 'url', url: maskUrl(res.finalUrl), requestedUrl: maskUrl(url), status: res.status, contentType: res.contentType, accept, redirects: res.redirects, bytes: res.bytes, baseUrl: maskUrl(res.finalUrl) },
361
+ meta: { kind: 'url', url: shownFinal, requestedUrl: movedUserinfoMask(url) ?? maskUrl(url), status: res.status, contentType: res.contentType, accept, redirects: res.redirects, bytes: res.bytes, baseUrl: shownFinal },
359
362
  body: res.body,
360
363
  base: res.finalUrl,
364
+ ...(res.shownFinalUrl !== undefined ? { baseMasked: true } : {}),
361
365
  };
362
366
  }
363
367
  function emit(report, args, io) {
@@ -64,7 +64,8 @@ const linkText = (l, other) => (l.masked || other?.masked ? '***' : redactText(l
64
64
  // `user:secret@host.example#a=b` has no other delimiter, so after maskHref the shape would no longer be recognised.
65
65
  // movedUserinfoMask reads the written target first: a target such as `https:/user:secret@host.example/x` resolves
66
66
  // against a base of the same scheme into a path that holds the user information, and only the scheme is shown then.
67
- const linkHref = (l, href) => (l.masked ? '***' : movedUserinfoMask(l.rawHref) ?? maskBareUserinfo(maskHref(maskBareUserinfo(href))));
67
+ // A link resolved against a base that hides user information is shown as written (baseMasked, markBaseMaskedLinks).
68
+ const linkHref = (l, href) => (l.masked ? '***' : movedUserinfoMask(l.rawHref) ?? maskBareUserinfo(maskHref(maskBareUserinfo(l.baseMasked ? l.rawHref : href))));
68
69
  /**
69
70
  * Pairs the HTML block's links with the Markdown block's, in three steps.
70
71
  *
@@ -37,6 +37,10 @@ export interface FetchResult {
37
37
  bytes: number;
38
38
  redirects: number;
39
39
  accept: string;
40
+ /** Set only when a followed redirect wrote a Location that movedUserinfoMask reads as hiding user information, as
41
+ * in user_name:secret@host.example. The final address then carries that text in its path, so a report shows this,
42
+ * the scheme, two slashes, three asterisks and a slash, in its place, and the links resolved against it as written. */
43
+ shownFinalUrl?: string;
40
44
  }
41
45
  export declare function validateUrl(input: string): URL;
42
46
  /**
package/dist/src/fetch.js CHANGED
@@ -7,7 +7,7 @@ import https from 'node:https';
7
7
  import dns from 'node:dns';
8
8
  import zlib from 'node:zlib';
9
9
  import { assertPublicHost, assertPublicResolved, BlockedAddressError, ipVersion } from './netguard.js';
10
- import { maskUrl, redactText } from './normalize.js';
10
+ import { maskBareUserinfo, maskUrl, movedUserinfoMask, redactText } from './normalize.js';
11
11
  import { TOOL_NAME, TOOL_VERSION } from './version.js';
12
12
  export class FetchError extends Error {
13
13
  kind;
@@ -16,7 +16,10 @@ export class FetchError extends Error {
16
16
  super(message);
17
17
  this.name = 'FetchError';
18
18
  this.kind = kind;
19
- this.url = maskUrl(url);
19
+ // movedUserinfoMask first: maskUrl showed --url 'CORP\erik:secret@host/p' as given (F2 of the seventh check).
20
+ // maskBareUserinfo after maskUrl: a refused user:secret@host.example/p, as a --url or a Location, is a URL with the
21
+ // scheme "user" and no authority, so maskUrl kept it whole (finding 1 of the tenth check).
22
+ this.url = movedUserinfoMask(url) ?? maskBareUserinfo(maskUrl(url));
20
23
  }
21
24
  }
22
25
  const defaultResolver = async (hostname) => {
@@ -29,7 +32,7 @@ export function validateUrl(input) {
29
32
  u = new URL(input);
30
33
  }
31
34
  catch {
32
- throw new FetchError('invalid_url', input, `Not a valid absolute URL: ${maskUrl(input)}`);
35
+ throw new FetchError('invalid_url', input, `Not a valid absolute URL: ${movedUserinfoMask(input) ?? maskUrl(input)}`);
33
36
  }
34
37
  if (u.protocol !== 'http:' && u.protocol !== 'https:') {
35
38
  throw new FetchError('protocol', input, `Only http and https URLs are fetched (got ${u.protocol}).`);
@@ -387,34 +390,60 @@ async function fetchWithDeadline(input, options, maxRedirects, deadline) {
387
390
  let url = validateUrl(input);
388
391
  const visited = new Set();
389
392
  let redirects = 0;
393
+ // A followed Location that movedUserinfoMask reads as hiding user information, as user_name:secret@host.example,
394
+ // resolves into a path that holds the secret, and every later address keeps it. From that hop on the address is
395
+ // named as its scheme and "//***/", in an error as in the result (the class of n1 of the independent rerun of
396
+ // 2026-11-22, found in this fetch by reading it).
397
+ // A typed --url of these shapes, as in http://host.example:8080\erik:secret@other.example/p, which the parser reads as
398
+ // a host, a port and a path, is named the same way from the first request on (L1 of the ninth check).
399
+ let shown = movedUserinfoMask(input) !== null ? `${url.protocol}//***/` : null;
400
+ const named = (u) => shown ?? maskUrl(u.href);
390
401
  for (;;) {
391
402
  if (visited.has(url.href))
392
- throw new FetchError('redirect_loop', url.href, `Redirect loop detected at ${maskUrl(url.href)}.`);
403
+ throw new FetchError('redirect_loop', shown === null ? url.href : shown, `Redirect loop detected at ${named(url)}.`);
393
404
  visited.add(url.href);
394
405
  let address;
406
+ let res;
395
407
  try {
396
- address = await deadline.race(pickAddress(url.hostname, options));
408
+ try {
409
+ address = await deadline.race(pickAddress(url.hostname, options));
410
+ }
411
+ catch (err) {
412
+ if (err instanceof BlockedAddressError)
413
+ throw new FetchError('blocked', url.href, err.message);
414
+ throw err;
415
+ }
416
+ res = await deadline.race(requestOnce(url, address, options, deadline));
397
417
  }
398
418
  catch (err) {
399
- if (err instanceof BlockedAddressError)
400
- throw new FetchError('blocked', url.href, err.message);
419
+ if (shown !== null && err instanceof FetchError)
420
+ err.url = shown;
401
421
  throw err;
402
422
  }
403
- const res = await deadline.race(requestOnce(url, address, options, deadline));
404
423
  if (REDIRECT_STATUSES.has(res.status)) {
405
424
  const loc = res.headers['location'];
425
+ // Both name the address after a hiding hop as shown, not as resolved (N1 of the eighth check).
406
426
  if (!loc)
407
- throw new FetchError('protocol', url.href, `HTTP ${res.status} without a Location header.`);
427
+ throw new FetchError('protocol', shown === null ? url.href : shown, `HTTP ${res.status} without a Location header.`);
408
428
  if (redirects >= maxRedirects)
409
- throw new FetchError('too_many_redirects', url.href, `More than ${maxRedirects} redirects.`);
429
+ throw new FetchError('too_many_redirects', shown === null ? url.href : shown, `More than ${maxRedirects} redirects.`);
410
430
  let next;
411
431
  try {
412
432
  next = new URL(loc, url);
413
433
  }
414
434
  catch {
415
- throw new FetchError('protocol', url.href, `Invalid redirect target: ${maskUrl(loc)}`);
435
+ throw new FetchError('protocol', shown === null ? url.href : shown, `Invalid redirect target: ${movedUserinfoMask(loc) ?? maskUrl(loc)}`);
436
+ }
437
+ if (shown === null && movedUserinfoMask(loc) !== null)
438
+ shown = `${next.protocol}//***/`;
439
+ try {
440
+ url = validateUrl(next.href);
441
+ }
442
+ catch (err) {
443
+ if (shown !== null && err instanceof FetchError)
444
+ err.url = shown;
445
+ throw err;
416
446
  }
417
- url = validateUrl(next.href);
418
447
  redirects++;
419
448
  continue;
420
449
  }
@@ -428,6 +457,7 @@ async function fetchWithDeadline(input, options, maxRedirects, deadline) {
428
457
  bytes: res.bytes,
429
458
  redirects,
430
459
  accept: options.accept,
460
+ ...(shown !== null ? { shownFinalUrl: shown } : {}),
431
461
  };
432
462
  }
433
463
  }
@@ -7,6 +7,8 @@ export interface HtmlExtractOptions {
7
7
  selector?: string;
8
8
  /** Base URL for resolving relative links; a <base href> in the document takes precedence. */
9
9
  baseUrl?: string | null;
10
+ /** The base came from a redirect whose Location hides user information (markBaseMaskedLinks). */
11
+ baseMasked?: boolean;
10
12
  /** Deepest element nesting accepted, counted from the document root. Default MAX_NESTING_DEPTH. */
11
13
  maxDepth?: number;
12
14
  }
package/dist/src/html.js CHANGED
@@ -3,7 +3,7 @@
3
3
  import { parseDocument } from 'htmlparser2';
4
4
  import { selectAll, selectOne } from 'css-select';
5
5
  import { Element, Text } from 'domhandler';
6
- import { extractNumbers, looseNormalize, normalizeCode, redactText, resolveHref, shownField, shownNormalize, stripControlChars, strictNormalize } from './normalize.js';
6
+ import { extractNumbers, looseNormalize, markBaseMaskedLinks, normalizeCode, redactText, resolveHref, shownField, shownNormalize, stripControlChars, strictNormalize } from './normalize.js';
7
7
  export class HtmlExtractError extends Error {
8
8
  /** The user-supplied value the message names (here, --selector), capped the way the hosted validator's cut()
9
9
  * (src/worker.ts in turva-worker) caps a reflected value: in its own field, not only interpolated into the sentence, and bounded so an
@@ -851,5 +851,7 @@ export function extractHtml(source, options = {}) {
851
851
  handleBlock(ctx, root);
852
852
  else
853
853
  walk(ctx, root);
854
+ // The written <base href> is read too: its resolved form has lost the backslash that marks the shape.
855
+ markBaseMaskedLinks(ctx.blocks, [options.baseUrl, base, baseEl instanceof Element ? baseEl.attribs['href'] : null], options.baseMasked ?? false);
854
856
  return { blocks: ctx.blocks, strategy: profile === 'generic' ? strategy : `${strategy};profile:starlight`, confidence, notes, issues };
855
857
  }
@@ -1,6 +1,8 @@
1
1
  import type { Extraction } from './model.js';
2
2
  export interface MarkdownExtractOptions {
3
3
  baseUrl?: string | null;
4
+ /** The base came from a redirect whose Location hides user information (markBaseMaskedLinks). */
5
+ baseMasked?: boolean;
4
6
  /**
5
7
  * 'keep' (default): nothing is removed; a document that starts with a fence that looks like YAML front
6
8
  * matter is compared as written and flagged with a warning. 'strip': the user has said the document
@@ -5,7 +5,7 @@ import { gfmFromMarkdown } from 'mdast-util-gfm';
5
5
  import { BLOCK_TAGS, extractHtml, HtmlDepthError, MAX_NESTING_DEPTH, opensExcludedSubtree } from './html.js';
6
6
  import { parseDocument, Parser } from 'htmlparser2';
7
7
  import { Element, Text } from 'domhandler';
8
- import { bareUserinfoSpansOf, excerpt, extractNumbers, insideHiddenUrlPart, insideUserinfoSpan, LinkTargetError, looseNormalize, MAX_LINK_TARGET_CHARS, normalizeCode, resolveHref, shownField, shownNormalize, strictNormalize, userinfoSpansOf } from './normalize.js';
8
+ import { bareUserinfoSpansOf, excerpt, extractNumbers, insideHiddenUrlPart, insideUserinfoSpan, LinkTargetError, looseNormalize, markBaseMaskedLinks, MAX_LINK_TARGET_CHARS, normalizeCode, resolveHref, shownField, shownNormalize, strictNormalize, userinfoSpansOf } from './normalize.js';
9
9
  export class MarkdownExtractError extends Error {
10
10
  }
11
11
  /** Deepest node nesting of a Markdown tree, counted with an explicit stack. */
@@ -612,5 +612,6 @@ export function extractMarkdown(source, options = {}) {
612
612
  if (i.code !== 'MARKDOWN_FRONT_MATTER_STRIPPED' && i.line !== undefined)
613
613
  i.line += fm.skippedLines;
614
614
  }
615
+ markBaseMaskedLinks(ctx.blocks, [options.baseUrl], options.baseMasked ?? false);
615
616
  return { blocks: ctx.blocks, strategy: 'markdown', confidence: 'high', notes: ctx.notes, issues: ctx.issues };
616
617
  }
@@ -9,6 +9,9 @@ export interface Link {
9
9
  rawHref: string;
10
10
  /** Href resolved against the document base, or null when it could not be resolved. */
11
11
  resolved: string | null;
12
+ /** The base the target was resolved against hides user information, so a report shows rawHref in place of
13
+ * resolved (markBaseMaskedLinks). Never compared. */
14
+ baseMasked?: boolean;
12
15
  /** The link was made by GFM out of a hidden part of a URL (a query value, the fragment or user information), so
13
16
  * a report shows neither its text nor its target. See insideHiddenUrlPart in normalize.ts. */
14
17
  masked?: boolean;
@@ -206,6 +206,10 @@ export declare function maskHref(href: string): string;
206
206
  * target as a relative path. Only *** is shown then.
207
207
  * - a relative target with a "?" or "#" before its last "@" and a colon between them, as in `u?x:secret@host`,
208
208
  * which put the secret into a query name. Only *** is shown.
209
+ * - a relative target with no "/" before its last "@" and a colon before that "@", when no scheme word stands before
210
+ * the colon: a Windows domain user as in `CORP\erik:secret@host/p`, an empty user name as in `:secret@host/p` and an
211
+ * "@" in the user name as in `erik@:secret@host/p`. The parser resolves each of them as a path, and maskBareUserinfo
212
+ * needs a label. Only *** is shown (independent rerun of 0.2.41, 2026-11-22).
209
213
  *
210
214
  * Not masked, and named in the README: a password that starts with "/" or with digits and "/", as in
211
215
  * `https://user:/secret@host`, which the parser reads as a host, a port and a path and which text alone cannot tell
@@ -213,6 +217,20 @@ export declare function maskHref(href: string): string;
213
217
  * `/user:secret@host`, which both readers take as a path.
214
218
  */
215
219
  export declare function movedUserinfoMask(written: string): string | null;
220
+ /**
221
+ * Marks the links of the blocks whose written target is relative, when the base they were resolved against hides user
222
+ * information: either baseMasked says so (a base that a redirect with such a Location produced) or movedUserinfoMask
223
+ * reads the base itself as one of its shapes, as in `https://CORP\erik:secret@host/dir/`. The parser reads that base
224
+ * as host "corp" and the user information as its path, so every relative link resolved against it carried the secret,
225
+ * and a report showed it (n6 of the rerun of 0.2.41, 2026-11-22). A marked link is shown as it was written, not as it
226
+ * was resolved. Display only: the comparison keeps the resolved target.
227
+ */
228
+ export declare function markBaseMaskedLinks(blocks: ReadonlyArray<{
229
+ links: Array<{
230
+ rawHref: string;
231
+ baseMasked?: boolean;
232
+ }>;
233
+ }>, bases: ReadonlyArray<string | null | undefined>, baseMasked: boolean): void;
216
234
  /** Describes how two hrefs differ without revealing masked parts. */
217
235
  export declare function hrefDifference(a: string, b: string): string;
218
236
  export type HrefRelation = 'same' | 'different' | 'uncertain';
@@ -1095,6 +1095,10 @@ const EDGE_INVISIBLE = new RegExp('^[\\s' + String.fromCharCode(0x85, 0x180e, 0x
1095
1095
  * target as a relative path. Only *** is shown then.
1096
1096
  * - a relative target with a "?" or "#" before its last "@" and a colon between them, as in `u?x:secret@host`,
1097
1097
  * which put the secret into a query name. Only *** is shown.
1098
+ * - a relative target with no "/" before its last "@" and a colon before that "@", when no scheme word stands before
1099
+ * the colon: a Windows domain user as in `CORP\erik:secret@host/p`, an empty user name as in `:secret@host/p` and an
1100
+ * "@" in the user name as in `erik@:secret@host/p`. The parser resolves each of them as a path, and maskBareUserinfo
1101
+ * needs a label. Only *** is shown (independent rerun of 0.2.41, 2026-11-22).
1098
1102
  *
1099
1103
  * Not masked, and named in the README: a password that starts with "/" or with digits and "/", as in
1100
1104
  * `https://user:/secret@host`, which the parser reads as a host, a port and a path and which text alone cannot tell
@@ -1126,8 +1130,14 @@ export function movedUserinfoMask(written) {
1126
1130
  if (word === null) {
1127
1131
  // A relative target with a ? or # before its last @ and a colon between them, as in u?x:secret@host, put the
1128
1132
  // secret into a query name against a base (fifth check), so nothing of it is shown.
1133
+ const lastAt = h.lastIndexOf('@');
1129
1134
  const cut = h.search(/[?#]/);
1130
- return cut >= 0 && h.slice(cut, h.lastIndexOf('@')).includes(':') ? '***' : null;
1135
+ if (cut >= 0 && h.slice(cut, lastAt).includes(':'))
1136
+ return '***';
1137
+ // A colon before the last @ and no slash before it, with no scheme word in front of the colon: CORP\erik:secret@,
1138
+ // :secret@ and erik@:secret@ resolved as a path and were shown whole (n3 to n5 of the rerun of 0.2.41).
1139
+ const before = h.slice(0, lastAt);
1140
+ return before.includes(':') && !before.includes('/') ? '***' : null;
1131
1141
  }
1132
1142
  if (special)
1133
1143
  return shown;
@@ -1157,6 +1167,31 @@ export function movedUserinfoMask(written) {
1157
1167
  }
1158
1168
  return null;
1159
1169
  }
1170
+ /**
1171
+ * Marks the links of the blocks whose written target is relative, when the base they were resolved against hides user
1172
+ * information: either baseMasked says so (a base that a redirect with such a Location produced) or movedUserinfoMask
1173
+ * reads the base itself as one of its shapes, as in `https://CORP\erik:secret@host/dir/`. The parser reads that base
1174
+ * as host "corp" and the user information as its path, so every relative link resolved against it carried the secret,
1175
+ * and a report showed it (n6 of the rerun of 0.2.41, 2026-11-22). A marked link is shown as it was written, not as it
1176
+ * was resolved. Display only: the comparison keeps the resolved target.
1177
+ */
1178
+ export function markBaseMaskedLinks(blocks, bases, baseMasked) {
1179
+ if (!baseMasked && !bases.some((b) => typeof b === 'string' && movedUserinfoMask(b) !== null))
1180
+ return;
1181
+ for (const block of blocks) {
1182
+ for (const link of block.links) {
1183
+ let absolute = false;
1184
+ try {
1185
+ absolute = resolveHref(link.rawHref, null) !== null;
1186
+ }
1187
+ catch {
1188
+ absolute = false;
1189
+ }
1190
+ if (!absolute)
1191
+ link.baseMasked = true;
1192
+ }
1193
+ }
1194
+ }
1160
1195
  /**
1161
1196
  * The href without its user information. The authority is found where the URL parser looks for it: after
1162
1197
  * "scheme:" and any slashes or backslashes for a special scheme, after "//" for any other scheme, and after two
@@ -1,10 +1,29 @@
1
1
  // Report rendering: human-readable text and JSON. No ANSI colours anywhere.
2
2
  import { TOOL_NAME } from './version.js';
3
- import { redactText } from './normalize.js';
3
+ import { movedUserinfoMask, redactText } from './normalize.js';
4
4
  /** Reporting boundary: every string that leaves the tool goes through redactText. Internal comparison
5
5
  * has already happened on the original values. */
6
6
  export function redactReport(report) {
7
- return mapStrings(report, redactText);
7
+ return mapStrings(withSourceAddressesMasked(report), redactText);
8
+ }
9
+ /** The source addresses (url, requestedUrl and baseUrl of each side) read through movedUserinfoMask first. A library
10
+ * caller passes meta.baseUrl as it is, and redactText showed https://CORP\erik:secret@host/dir/ whole (n6 of the
11
+ * independent rerun of 0.2.41, 2026-11-22). Only fields that are there are touched. */
12
+ function withSourceAddressesMasked(report) {
13
+ if (!report || typeof report !== 'object' || !report.sources)
14
+ return report;
15
+ const mask = (s) => {
16
+ if (!s || typeof s !== 'object')
17
+ return s;
18
+ const out = { ...s };
19
+ for (const k of ['url', 'requestedUrl', 'baseUrl']) {
20
+ const v = out[k];
21
+ if (typeof v === 'string')
22
+ out[k] = movedUserinfoMask(v) ?? v;
23
+ }
24
+ return out;
25
+ };
26
+ return { ...report, sources: { ...report.sources, html: mask(report.sources.html), markdown: mask(report.sources.markdown) } };
8
27
  }
9
28
  /** A copy of the value with fn applied to every string in it, however deep. */
10
29
  function mapStrings(value, fn) {
package/dist/src/run.d.ts CHANGED
@@ -22,6 +22,9 @@ export interface SourceInput {
22
22
  body: string;
23
23
  /** Unmasked base URL for link resolution; never written to the report. */
24
24
  base: string | null;
25
+ /** The base came from a redirect whose Location hides user information, so links resolved against it are shown as
26
+ * written (fetchUrl sets shownFinalUrl then). */
27
+ baseMasked?: boolean;
25
28
  }
26
29
  export interface RunOptions {
27
30
  htmlProfile?: 'generic' | 'starlight';
package/dist/src/run.js CHANGED
@@ -136,14 +136,14 @@ export function run(html, markdown, options) {
136
136
  throw new TypeError(`Limit maxNestingDepth must be a positive number (got ${String(maxDepth)}).`);
137
137
  let h;
138
138
  try {
139
- h = extractHtml(html.body, { profile: options.htmlProfile, selector: options.selector, baseUrl: html.base, maxDepth });
139
+ h = extractHtml(html.body, { profile: options.htmlProfile, selector: options.selector, baseUrl: html.base, baseMasked: html.baseMasked ?? false, maxDepth });
140
140
  }
141
141
  catch (err) {
142
142
  throw extractionError('HTML', err) ?? err;
143
143
  }
144
144
  let m;
145
145
  try {
146
- m = extractMarkdown(markdown.body, { baseUrl: markdown.base, frontMatter: options.frontMatter ?? 'keep', maxDepth });
146
+ m = extractMarkdown(markdown.body, { baseUrl: markdown.base, baseMasked: markdown.baseMasked ?? false, frontMatter: options.frontMatter ?? 'keep', maxDepth });
147
147
  }
148
148
  catch (err) {
149
149
  throw extractionError('Markdown', err) ?? err;
@@ -1,2 +1,2 @@
1
1
  export declare const TOOL_NAME = "markdown-parity-check";
2
- export declare const TOOL_VERSION = "0.2.41";
2
+ export declare const TOOL_VERSION = "0.2.42";
@@ -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.41';
5
+ export const TOOL_VERSION = '0.2.42';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-parity-check",
3
- "version": "0.2.41",
3
+ "version": "0.2.42",
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",