markdown-parity-check 0.2.39 → 0.2.41

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.39 on 2026-11-14. 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.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:
82
82
 
83
83
  ```text
84
- markdown-parity-check 0.2.39 (offline mode)
84
+ markdown-parity-check 0.2.41 (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`, an scp-style `git@host:path` and a scheme-less `user:password@host`. 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. 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`.
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
 
@@ -223,7 +223,7 @@ The test suite runs the bounded case and asserts no time. When a limit is exceed
223
223
 
224
224
  The library has no time limit and no memory limit of its own. A program that compares untrusted documents needs a time limit and a memory limit of its own, enforced outside the calling thread, for example in a worker thread, in a separate process or in an isolate with a CPU limit. `run` is synchronous, so a timer in the same thread cannot interrupt it, and the command line uses a worker thread for that reason. A link target over 8192 characters is a `RunError`, as described under the limits of the method.
225
225
 
226
- Some costs come from the parsers and are not bounded by this package. The table rule of `micromark-extension-gfm` and the bare link rule of `mdast-util-find-and-replace` take more than linear time on very large inputs. In hand timings on one development machine, a Markdown table of 10 000 one-cell rows and one row of 30 000 cells, under 250 kB, took tens of seconds to parse, and 100 000 bare links in one paragraph, 2.8 MB, took tens of seconds as well. A deeply nested HTML document needs memory in proportion to its blocks times their nesting depth. A document of 650 000 paragraphs inside 1 000 nested elements, 5 MiB, ran out of memory at about 4 GB, which ends a library process. The command line stops the same run with exit code 2, and the test suite does not repeat these timings.
226
+ Some costs come from the parsers and are not bounded by this package. The table rule of `micromark-extension-gfm` and the bare link rule of `mdast-util-find-and-replace` take more than linear time, and for a table the cost shows at ordinary sizes. In hand timings of `run` with Node.js 26 on one development machine on 2026-11-22, a two-column table of 8 KiB took about 40 ms, 16 KiB about 110 ms, 32 KiB about 600 ms and 64 KiB, 6 552 rows, about 3 s, so from 16 KiB on each doubling took about five times as long. In earlier hand timings a table of 10 000 one-cell rows and one row of 30 000 cells, under 250 kB, took tens of seconds to parse, and 100 000 bare links in one paragraph, 2.8 MB, took tens of seconds as well. A deeply nested HTML document needs memory in proportion to its blocks times their nesting depth. A document of 650 000 paragraphs inside 1 000 nested elements, 5 MiB, ran out of memory at about 4 GB, which ends a library process. The command line stops the same run with exit code 2, and the test suite does not repeat these timings.
227
227
 
228
228
  The caller fetches the pages and decides which addresses are allowed. The address policy that the command applies is exported as `assertPublicHost` and `isPublicAddress`. `assertPublicHost` takes `url.hostname` of a parsed `URL`, because the URL parser has already written a literal such as `2130706433` or `0x7f.0.0.1` as dotted decimal by then. A caller that checks the host and the resolved addresses and then lets `fetch()` resolve the name again can be sent to another address by a DNS answer that changes in between. The package exports no helper that pins the checked address. The command connects to the address it checked.
229
229
 
@@ -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.39 --ignore-scripts && npm audit signatures
275
+ mkdir verify-mpc && cd verify-mpc && npm init -y && npm install markdown-parity-check@0.2.41 --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.39` must point at that same commit, and `gh api repos/erekola/markdown-parity-check/commits/v0.2.39 --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.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.
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.39\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.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";
4
4
  export declare class CliError extends Error {
5
5
  }
6
6
  export interface CliArgs {
@@ -1,6 +1,6 @@
1
1
  // The comparison core: aligns blocks and turns the alignment into findings. Pure and network-free.
2
2
  import { align, resolveLimits, AlignmentLimitError, UNCERTAIN_THRESHOLD } from './align.js';
3
- import { codeWhitespaceKey, excerpt, hrefDifference, looseNormalize, maskHref, redactText, relativeHrefRelation, textKey, trimHref, visibleNumbers } from './normalize.js';
3
+ import { codeWhitespaceKey, excerpt, hrefDifference, looseNormalize, maskBareUserinfo, maskHref, movedUserinfoMask, redactText, relativeHrefRelation, textKey, trimHref, visibleNumbers } from './normalize.js';
4
4
  // The excerpt masks the whole block text before it cuts it, so it is computed once per block. Up to 0.2.11 every
5
5
  // finding computed it again, and a block with thousands of link findings did that thousands of times (0.2.12).
6
6
  const sides = new WeakMap();
@@ -60,7 +60,11 @@ export function diffNumbers(a, b) {
60
60
  }
61
61
  // What a finding shows of a link. A link GFM made out of a hidden part of a URL shows neither text nor target.
62
62
  const linkText = (l, other) => (l.masked || other?.masked ? '***' : redactText(l.shown ?? l.text));
63
- const linkHref = (l, href) => (l.masked ? '***' : maskHref(href));
63
+ // maskBareUserinfo runs before maskHref as well as after it: maskHref drops the fragment, and a target such as
64
+ // `user:secret@host.example#a=b` has no other delimiter, so after maskHref the shape would no longer be recognised.
65
+ // movedUserinfoMask reads the written target first: a target such as `https:/user:secret@host.example/x` resolves
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))));
64
68
  /**
65
69
  * Pairs the HTML block's links with the Markdown block's, in three steps.
66
70
  *
@@ -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 { 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, 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. */
@@ -226,7 +226,8 @@ function inline(ctx, node, run) {
226
226
  // A GFM literal autolink starts with neither [ nor <. One that GFM found inside a hidden part of another URL
227
227
  // is compared as usual but shown masked (0.2.12). So is one that starts inside the user information of an
228
228
  // address, scheme included, which GFM cuts at white space: the head of "https://user:pa ss@host/" is a link of
229
- // its own, and so is the tail "ss@host" read as an e-mail address.
229
+ // its own, and so is the tail "ss@host" read as an e-mail address. The same holds for the "secret@host.example"
230
+ // that GFM reads out of user:secret@host.example/path, which has no scheme separator (0.2.40).
230
231
  const at = node.position?.start.offset;
231
232
  if (at !== undefined && ctx.source[at] !== '[' && ctx.source[at] !== '<') {
232
233
  if (insideHiddenUrlPart(ctx.source, at))
@@ -236,6 +237,11 @@ function inline(ctx, node, run) {
236
237
  if (insideUserinfoSpan(ctx.userinfo, at))
237
238
  link.masked = true;
238
239
  }
240
+ if (!link.masked && ctx.source.includes('@')) {
241
+ ctx.bareUserinfo ??= bareUserinfoSpansOf(ctx.source);
242
+ if (insideUserinfoSpan(ctx.bareUserinfo, at))
243
+ link.masked = true;
244
+ }
239
245
  }
240
246
  run.links.push(link);
241
247
  run.links.push(...inner.links);
@@ -108,10 +108,38 @@ export declare function dropAuthorityControls(text: string): string;
108
108
  export declare function userinfoSpansOf(text: string): UserinfoSpan[];
109
109
  /** Whether position at lies in a user information of spans, scheme included, the "@" included. */
110
110
  export declare function insideUserinfoSpan(spans: UserinfoSpan[], at: number): boolean;
111
+ /**
112
+ * The credential-shaped "label:name@host" of a text that has no scheme separator, as in user:secret@host.example/p
113
+ * (0.2.40, found by an independent check of 0.2.39). The URL parser reads "user:" as a scheme and the rest as an opaque
114
+ * path, so maskHref found no user information, and GFM read "secret@host.example" as an e-mail address, so the
115
+ * secret reached a report as an excerpt and as the text and the target of a link. A span is found in a run (RUN) when
116
+ * a label, the letters, digits and the characters + . - that start with a letter and follow no scheme character,
117
+ * is followed by a colon and then by text that holds an "@" before the first slash, backslash, question mark or number
118
+ * sign, and that delimiter, which must be there, makes the address a URL-like one: a slash or a backslash, a query that
119
+ * starts with a name and an equals sign, or a number sign with an equals sign later in the run. The text after the
120
+ * last "@" up to the delimiter must be a host name (isBareHostText). The user information is the text between the
121
+ * colon and that "@", and it must not be empty.
122
+ *
123
+ * Not a span, so shown as written: a special scheme (https:user@host/ is masked by the other rules), a scheme of
124
+ * ADDRESS_SCHEMES, a label that follows a slash (the authority rules read //name:secret@host/), an address that
125
+ * no delimiter follows, as in "Contact:jane@example.com", and a question mark or a number sign that is not followed by
126
+ * a value, as in "Did you mean To:jane@example.com?". "label:jane@example.com" with no space is therefore shown
127
+ * unless a path, a query value or a fragment value follows, because text alone cannot tell a label from a user name.
128
+ * A failed candidate is scanned to its own delimiter and a found one to its "@", so the scan stays linear. The result
129
+ * is a display aid and is never part of a comparison key.
130
+ */
131
+ export declare function findBareUserinfoSpans(text: string): UserinfoSpan[];
132
+ /** Masks the user information of every "label:name@host/path" that findBareUserinfoSpans finds, and leaves the label,
133
+ * the host and the rest as they are: user:secret@host.example/p?x=1 reads user:***@host.example/p?x=1. Display only. */
134
+ export declare function maskBareUserinfo(text: string): string;
135
+ /** The spans of findBareUserinfoSpans for a source text, with the characters that stripControlChars removes read as
136
+ * a letter, which keeps every position and does not end a run or a label. */
137
+ export declare function bareUserinfoSpansOf(text: string): UserinfoSpan[];
111
138
  /** Masks user information, query values and fragments of every URL-like run in a piece of report text.
112
139
  * maskParenUserinfo and maskAuthorityUserinfo run first, for the shapes the runs of RUN cannot see as one URL, and
113
- * stripControlChars runs last so a raw ANSI escape from a compared page or an argument cannot reach a plain
114
- * --format text report (0.2.16, found by an outside review 2026-09-28). */
140
+ * maskBareUserinfo for the name:secret@host shape without a scheme separator. stripControlChars runs last so a raw
141
+ * ANSI escape from a compared page or an argument cannot reach a plain --format text report (0.2.16, found by an
142
+ * outside review 2026-09-28). */
115
143
  export declare function redactText(text: string): string;
116
144
  /**
117
145
  * The text with the parts that maskHref hides taken out of every URL-like run: user information, query values
@@ -151,6 +179,40 @@ export declare function maskUrl(url: string): string;
151
179
  * display. The user name goes with the password, because either one can be the secret. Up to 0.2.9 both
152
180
  * stayed in the output, and so in the error of a refused URL (found by an outside review 2026-09-22). */
153
181
  export declare function maskHref(href: string): string;
182
+ /**
183
+ * What a report shows in place of a link target whose user information the URL parser and a person may read at
184
+ * different places, or null when maskHref and maskBareUserinfo show the target safely. It is decided from the written
185
+ * target alone, whatever the base, so one link reads the same in every finding, the way turva-llms-txt-validator
186
+ * shows an ambiguous address: only the scheme and "//***", or "***" when the text before the colon may itself be the
187
+ * user name. Found by an outside fuzz run of 0.2.40 on 2026-11-22 (P3-1) and by four independent checks of 0.2.41
188
+ * before release. Only a target that holds an "@" counts, and these shapes are masked:
189
+ *
190
+ * - a special scheme with fewer than two slashes or backslashes after its colon, as in `https:/user:secret@host/x`.
191
+ * Against a base of the same scheme the parser reads a relative path, so `https://example.com/user:secret@host/x`
192
+ * was shown.
193
+ * - an authority, after two slashes (or backslashes, for a special scheme or no scheme), with a backslash, "?" or "#"
194
+ * before the last "@" and before the first "/", as in `https://CORP\erik:secret@host/x` or
195
+ * `https://user:x?secret@host/x`. The parser ends the host there, so the secret was shown in a path or as a query
196
+ * name. `https://example.com?e=a@b.com` reads the same way and is masked too.
197
+ * - an authority that the parser refuses, as with the port `pa` in `https://user:pa/ss?secret@host`.
198
+ * - a `file:` URL. Its host is empty, so `file:///user:secret@host` kept the user information in its path.
199
+ * - a non-special scheme with no "//", or with an empty authority as in `gopher:///user:secret@host`, whose text
200
+ * before the last "@" holds a colon, as in `gopher:user:secret@host`, which the parser reads as an opaque path. Not
201
+ * for an address scheme such as mailto, and not for `user:secret@host.example/p`, whose user name is the scheme
202
+ * word and which maskBareUserinfo masks.
203
+ * - a scheme word that the parser refuses, as in `user_name:secret@host`, `my_app:user:secret@host` or
204
+ * `ht tps:/user:secret@host`, which resolves as a relative path.
205
+ * - any target with an "@" after a leading Unicode space or U+FFFD, which the parser keeps, so it reads the whole
206
+ * target as a relative path. Only *** is shown then.
207
+ * - a relative target with a "?" or "#" before its last "@" and a colon between them, as in `u?x:secret@host`,
208
+ * which put the secret into a query name. Only *** is shown.
209
+ *
210
+ * Not masked, and named in the README: a password that starts with "/" or with digits and "/", as in
211
+ * `https://user:/secret@host`, which the parser reads as a host, a port and a path and which text alone cannot tell
212
+ * from a path that holds an "@", such as `https://localhost:8080/team@example.com`; and a relative path such as
213
+ * `/user:secret@host`, which both readers take as a path.
214
+ */
215
+ export declare function movedUserinfoMask(written: string): string | null;
154
216
  /** Describes how two hrefs differ without revealing masked parts. */
155
217
  export declare function hrefDifference(a: string, b: string): string;
156
218
  export type HrefRelation = 'same' | 'different' | 'uncertain';
@@ -804,15 +804,155 @@ export function insideUserinfoSpan(spans, at) {
804
804
  }
805
805
  return false;
806
806
  }
807
+ // Schemes whose address part is an e-mail address or a user at a host by design. "mailto:jane@example.com/x" and the
808
+ // like are shown as written, so the masking of a name and a secret before an "@" does not reach them.
809
+ const ADDRESS_SCHEMES = new Set(['mailto', 'xmpp', 'sip', 'sips', 'acct', 'im']);
810
+ /** Whether t[from, to) is a host name followed by an optional port, by the rule bareHostStart uses: dotted labels that
811
+ * end in a letters-only label of two or more characters or in an xn-- label, a dotted IPv4 address or localhost. A
812
+ * trailing dot, an empty label and a name with no dot other than localhost are not hosts. */
813
+ function isBareHostText(t, from, to) {
814
+ let end = to;
815
+ let k = to;
816
+ while (k > from && isDigit(t.charCodeAt(k - 1)))
817
+ k--;
818
+ if (k < to && k > from + 1 && t.charCodeAt(k - 1) === 0x3a)
819
+ end = k - 1;
820
+ if (end <= from)
821
+ return false;
822
+ let labels = 1;
823
+ let lastStart = from;
824
+ for (let i = from; i < end; i++) {
825
+ const c = t.charCodeAt(i);
826
+ if (c === 0x2e) {
827
+ if (i === lastStart || i + 1 >= end)
828
+ return false;
829
+ labels++;
830
+ lastStart = i + 1;
831
+ }
832
+ else if (!(isLetter(c) || isDigit(c) || c === 0x2d || c === 0x5f))
833
+ return false;
834
+ }
835
+ const name = t.slice(from, end);
836
+ if (labels === 1)
837
+ return name.replace(/\u017f/g, 's').toLowerCase() === 'localhost';
838
+ const last = t.slice(lastStart, end);
839
+ if (last.length >= 2 && /^[A-Za-z\u017f\u212a]+$/u.test(last))
840
+ return true;
841
+ if (last.length >= 5 && /^xn--[^_]*$/i.test(last))
842
+ return true;
843
+ return labels === 4 && /^\d{1,3}(?:\.\d{1,3}){3}$/.test(name);
844
+ }
845
+ /**
846
+ * The credential-shaped "label:name@host" of a text that has no scheme separator, as in user:secret@host.example/p
847
+ * (0.2.40, found by an independent check of 0.2.39). The URL parser reads "user:" as a scheme and the rest as an opaque
848
+ * path, so maskHref found no user information, and GFM read "secret@host.example" as an e-mail address, so the
849
+ * secret reached a report as an excerpt and as the text and the target of a link. A span is found in a run (RUN) when
850
+ * a label, the letters, digits and the characters + . - that start with a letter and follow no scheme character,
851
+ * is followed by a colon and then by text that holds an "@" before the first slash, backslash, question mark or number
852
+ * sign, and that delimiter, which must be there, makes the address a URL-like one: a slash or a backslash, a query that
853
+ * starts with a name and an equals sign, or a number sign with an equals sign later in the run. The text after the
854
+ * last "@" up to the delimiter must be a host name (isBareHostText). The user information is the text between the
855
+ * colon and that "@", and it must not be empty.
856
+ *
857
+ * Not a span, so shown as written: a special scheme (https:user@host/ is masked by the other rules), a scheme of
858
+ * ADDRESS_SCHEMES, a label that follows a slash (the authority rules read //name:secret@host/), an address that
859
+ * no delimiter follows, as in "Contact:jane@example.com", and a question mark or a number sign that is not followed by
860
+ * a value, as in "Did you mean To:jane@example.com?". "label:jane@example.com" with no space is therefore shown
861
+ * unless a path, a query value or a fragment value follows, because text alone cannot tell a label from a user name.
862
+ * A failed candidate is scanned to its own delimiter and a found one to its "@", so the scan stays linear. The result
863
+ * is a display aid and is never part of a comparison key.
864
+ */
865
+ export function findBareUserinfoSpans(text) {
866
+ const spans = [];
867
+ const runs = new RegExp(RUN.source, RUN.flags);
868
+ for (let run = runs.exec(text); run !== null; run = runs.exec(text)) {
869
+ const s = run.index;
870
+ const e = s + run[0].length;
871
+ if (!run[0].includes('@'))
872
+ continue;
873
+ let lastEquals = e - 1;
874
+ while (lastEquals >= s && text.charCodeAt(lastEquals) !== 0x3d)
875
+ lastEquals--;
876
+ let i = s;
877
+ while (i < e) {
878
+ if (!isLetter(text.charCodeAt(i)) || (i > s && isSchemeChar(text.charCodeAt(i - 1)))) {
879
+ i++;
880
+ continue;
881
+ }
882
+ let b = i;
883
+ while (b < e && isSchemeChar(text.charCodeAt(b)))
884
+ b++;
885
+ if (b + 1 >= e || text.charCodeAt(b) !== 0x3a) {
886
+ i = b;
887
+ continue;
888
+ }
889
+ let k = b + 1;
890
+ let lastAt = -1;
891
+ while (k < e) {
892
+ const c = text.charCodeAt(k);
893
+ if (c === 0x2f || c === 0x5c || c === 0x3f || c === 0x23)
894
+ break;
895
+ if (c === 0x40)
896
+ lastAt = k;
897
+ k++;
898
+ }
899
+ let ok = k < e && lastAt > b + 1 && isBareHostText(text, lastAt + 1, k);
900
+ if (ok) {
901
+ const d = text.charCodeAt(k);
902
+ if (d === 0x3f) {
903
+ let q = k + 1;
904
+ while (q < e && isParamChar(text.charCodeAt(q)))
905
+ q++;
906
+ ok = q > k + 1 && q < e && text.charCodeAt(q) === 0x3d;
907
+ }
908
+ else if (d === 0x23)
909
+ ok = lastEquals > k;
910
+ }
911
+ if (ok) {
912
+ const prev = i > s ? text.charCodeAt(i - 1) : -1;
913
+ ok = prev !== 0x2f && prev !== 0x5c && specialSchemeLength(text, i, e) !== b - i && !ADDRESS_SCHEMES.has(text.slice(i, b).toLowerCase());
914
+ }
915
+ if (ok) {
916
+ spans.push({ start: i, from: b + 1, at: lastAt });
917
+ i = lastAt + 1;
918
+ }
919
+ else
920
+ i = k;
921
+ }
922
+ }
923
+ return spans;
924
+ }
925
+ /** Masks the user information of every "label:name@host/path" that findBareUserinfoSpans finds, and leaves the label,
926
+ * the host and the rest as they are: user:secret@host.example/p?x=1 reads user:***@host.example/p?x=1. Display only. */
927
+ export function maskBareUserinfo(text) {
928
+ if (!text.includes('@'))
929
+ return text;
930
+ const spans = findBareUserinfoSpans(text);
931
+ if (spans.length === 0)
932
+ return text;
933
+ let out = '';
934
+ let pos = 0;
935
+ for (const s of spans) {
936
+ out += text.slice(pos, s.from) + '***@';
937
+ pos = s.at + 1;
938
+ }
939
+ return out + text.slice(pos);
940
+ }
941
+ /** The spans of findBareUserinfoSpans for a source text, with the characters that stripControlChars removes read as
942
+ * a letter, which keeps every position and does not end a run or a label. */
943
+ export function bareUserinfoSpansOf(text) {
944
+ return findBareUserinfoSpans(text.replace(CONTROL_CHARS, (m) => 'a'.repeat(m.length)));
945
+ }
807
946
  /** Masks user information, query values and fragments of every URL-like run in a piece of report text.
808
947
  * maskParenUserinfo and maskAuthorityUserinfo run first, for the shapes the runs of RUN cannot see as one URL, and
809
- * stripControlChars runs last so a raw ANSI escape from a compared page or an argument cannot reach a plain
810
- * --format text report (0.2.16, found by an outside review 2026-09-28). */
948
+ * maskBareUserinfo for the name:secret@host shape without a scheme separator. stripControlChars runs last so a raw
949
+ * ANSI escape from a compared page or an argument cannot reach a plain --format text report (0.2.16, found by an
950
+ * outside review 2026-09-28). */
811
951
  export function redactText(text) {
812
952
  // The control characters go first as well as last: a vertical tab, a form feed, U+2028 or U+0085 inside the user
813
953
  // information would otherwise end the authority for the masking and be removed afterwards, which left a credential
814
954
  // that read as a whole URL.
815
- return stripControlChars(rewriteUrlRuns(maskAuthorityUserinfo(maskParenUserinfo(stripControlChars(text)), true), maskHref));
955
+ return stripControlChars(rewriteUrlRuns(maskBareUserinfo(maskAuthorityUserinfo(maskParenUserinfo(stripControlChars(text)), true)), maskHref));
816
956
  }
817
957
  /**
818
958
  * The text with the parts that maskHref hides taken out of every URL-like run: user information, query values
@@ -925,6 +1065,98 @@ export function maskHref(href) {
925
1065
  }
926
1066
  }
927
1067
  const SPECIAL_SCHEMES = new Set(['ftp', 'file', 'http', 'https', 'ws', 'wss']);
1068
+ /** Leading characters a reader does not see but the URL parser keeps: the Unicode white space, U+0085, U+180E,
1069
+ * U+200B and U+FFFD, which the Markdown parser writes for a NUL. */
1070
+ const EDGE_INVISIBLE = new RegExp('^[\\s' + String.fromCharCode(0x85, 0x180e, 0x200b, 0xfffd) + ']+');
1071
+ /**
1072
+ * What a report shows in place of a link target whose user information the URL parser and a person may read at
1073
+ * different places, or null when maskHref and maskBareUserinfo show the target safely. It is decided from the written
1074
+ * target alone, whatever the base, so one link reads the same in every finding, the way turva-llms-txt-validator
1075
+ * shows an ambiguous address: only the scheme and "//***", or "***" when the text before the colon may itself be the
1076
+ * user name. Found by an outside fuzz run of 0.2.40 on 2026-11-22 (P3-1) and by four independent checks of 0.2.41
1077
+ * before release. Only a target that holds an "@" counts, and these shapes are masked:
1078
+ *
1079
+ * - a special scheme with fewer than two slashes or backslashes after its colon, as in `https:/user:secret@host/x`.
1080
+ * Against a base of the same scheme the parser reads a relative path, so `https://example.com/user:secret@host/x`
1081
+ * was shown.
1082
+ * - an authority, after two slashes (or backslashes, for a special scheme or no scheme), with a backslash, "?" or "#"
1083
+ * before the last "@" and before the first "/", as in `https://CORP\erik:secret@host/x` or
1084
+ * `https://user:x?secret@host/x`. The parser ends the host there, so the secret was shown in a path or as a query
1085
+ * name. `https://example.com?e=a@b.com` reads the same way and is masked too.
1086
+ * - an authority that the parser refuses, as with the port `pa` in `https://user:pa/ss?secret@host`.
1087
+ * - a `file:` URL. Its host is empty, so `file:///user:secret@host` kept the user information in its path.
1088
+ * - a non-special scheme with no "//", or with an empty authority as in `gopher:///user:secret@host`, whose text
1089
+ * before the last "@" holds a colon, as in `gopher:user:secret@host`, which the parser reads as an opaque path. Not
1090
+ * for an address scheme such as mailto, and not for `user:secret@host.example/p`, whose user name is the scheme
1091
+ * word and which maskBareUserinfo masks.
1092
+ * - a scheme word that the parser refuses, as in `user_name:secret@host`, `my_app:user:secret@host` or
1093
+ * `ht tps:/user:secret@host`, which resolves as a relative path.
1094
+ * - any target with an "@" after a leading Unicode space or U+FFFD, which the parser keeps, so it reads the whole
1095
+ * target as a relative path. Only *** is shown then.
1096
+ * - a relative target with a "?" or "#" before its last "@" and a colon between them, as in `u?x:secret@host`,
1097
+ * which put the secret into a query name. Only *** is shown.
1098
+ *
1099
+ * Not masked, and named in the README: a password that starts with "/" or with digits and "/", as in
1100
+ * `https://user:/secret@host`, which the parser reads as a host, a port and a path and which text alone cannot tell
1101
+ * from a path that holds an "@", such as `https://localhost:8080/team@example.com`; and a relative path such as
1102
+ * `/user:secret@host`, which both readers take as a path.
1103
+ */
1104
+ export function movedUserinfoMask(written) {
1105
+ const own = urlParserInput(written);
1106
+ const h = own.replace(EDGE_INVISIBLE, '');
1107
+ if (!h.includes('@'))
1108
+ return null;
1109
+ // A leading invisible character makes the parser read the whole target as a relative path, whatever follows it, so
1110
+ // nothing of it is shown (fifth independent check: U+2003 before user:secret@host/p or https:///user:secret@host).
1111
+ if (h !== own)
1112
+ return '***';
1113
+ // The scheme word runs to the first colon unless a slash, backslash, ?, # or @ comes first, so "ht tps:" is a word
1114
+ // the parser refuses, not a relative path (fifth check).
1115
+ const word = /^([^\/\\?#@:]+):/.exec(h);
1116
+ if (word !== null && !/^[a-z][a-z0-9+.-]*$/i.test(word[1]))
1117
+ return '***';
1118
+ const name = word === null ? '' : word[1].toLowerCase();
1119
+ if (ADDRESS_SCHEMES.has(name))
1120
+ return null;
1121
+ const special = word === null || SPECIAL_SCHEMES.has(name);
1122
+ const rest = word === null ? h : h.slice(word[0].length);
1123
+ const shown = word === null ? '//***' : `${name}://***`;
1124
+ const isSlash = (c) => c === 0x2f || (special && c === 0x5c);
1125
+ if (!(rest.length >= 2 && isSlash(rest.charCodeAt(0)) && isSlash(rest.charCodeAt(1)))) {
1126
+ if (word === null) {
1127
+ // A relative target with a ? or # before its last @ and a colon between them, as in u?x:secret@host, put the
1128
+ // secret into a query name against a base (fifth check), so nothing of it is shown.
1129
+ const cut = h.search(/[?#]/);
1130
+ return cut >= 0 && h.slice(cut, h.lastIndexOf('@')).includes(':') ? '***' : null;
1131
+ }
1132
+ if (special)
1133
+ return shown;
1134
+ return rest.slice(0, rest.lastIndexOf('@')).includes(':') ? `${name}:***` : null;
1135
+ }
1136
+ if (name === 'file')
1137
+ return shown;
1138
+ // A non-special scheme with an empty authority, as in gopher:///user:secret@host, keeps the rest in its path.
1139
+ if (!special && rest.charCodeAt(2) === 0x2f)
1140
+ return `${name}:***`;
1141
+ let k = 2;
1142
+ while (k < rest.length && isSlash(rest.charCodeAt(k)))
1143
+ k++;
1144
+ const tail = rest.slice(k);
1145
+ const lastAt = tail.lastIndexOf('@');
1146
+ if (lastAt <= 0)
1147
+ return null;
1148
+ const slash = tail.indexOf('/');
1149
+ const end = slash >= 0 && slash < lastAt ? slash : lastAt;
1150
+ if (/[\\?#]/.test(tail.slice(0, end)))
1151
+ return shown;
1152
+ try {
1153
+ new URL(word === null ? `https:${h}` : h);
1154
+ }
1155
+ catch {
1156
+ return shown;
1157
+ }
1158
+ return null;
1159
+ }
928
1160
  /**
929
1161
  * The href without its user information. The authority is found where the URL parser looks for it: after
930
1162
  * "scheme:" and any slashes or backslashes for a special scheme, after "//" for any other scheme, and after two
@@ -1,2 +1,2 @@
1
1
  export declare const TOOL_NAME = "markdown-parity-check";
2
- export declare const TOOL_VERSION = "0.2.39";
2
+ export declare const TOOL_VERSION = "0.2.41";
@@ -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.39';
5
+ export const TOOL_VERSION = '0.2.41';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-parity-check",
3
- "version": "0.2.39",
3
+ "version": "0.2.41",
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",