markdown-parity-check 0.2.28 → 0.2.29

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
@@ -69,7 +69,7 @@ Exit code 0 means the implemented checks found nothing to reject. It does not pr
69
69
  | `--format text` or `--format json` | Print a readable report, which is the default, or a structured one. |
70
70
  | `--output PATH` | Write the report to a file. An input file is never overwritten. |
71
71
  | `--strict` | Treat warnings as rejecting findings. |
72
- | `--timeout-ms MS` | Deadline per request. The default is 15 000 ms. The value must be a positive decimal integer no greater than 2147483647. |
72
+ | `--timeout-ms MS` | Deadline for each request and for the parsing and comparison step. The default is 15 000 ms, and a run that passes it stops with exit code 2. The value must be a positive decimal integer no greater than 2147483647. |
73
73
  | `--max-bytes N` | Limit on decoded bytes per response. The default is 5 MiB. The value must be a positive decimal integer no greater than 9007199254740991. |
74
74
  | `--help`, `-h` | Print the help. |
75
75
  | `--version`, `-V` | Print the version. |
@@ -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.28 on 2026-10-21. 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.29 on 2026-10-23. 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.28 (offline mode)
84
+ markdown-parity-check 0.2.29 (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)
@@ -245,10 +245,10 @@ Only after that check does it create the GitHub release with the verified tarbal
245
245
  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.
246
246
 
247
247
  ```sh
248
- mkdir verify-mpc && cd verify-mpc && npm init -y && npm install markdown-parity-check@0.2.28 --ignore-scripts && npm audit signatures
248
+ mkdir verify-mpc && cd verify-mpc && npm init -y && npm install markdown-parity-check@0.2.29 --ignore-scripts && npm audit signatures
249
249
  ```
250
250
 
251
- `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. Tag `v0.2.28` must point at that same commit, and `gh api repos/erekola/markdown-parity-check/commits/v0.2.28 --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.
251
+ `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. Tag `v0.2.29` must point at that same commit, and `gh api repos/erekola/markdown-parity-check/commits/v0.2.29 --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.
252
252
 
253
253
  ## Security
254
254
 
package/SECURITY.md CHANGED
@@ -12,7 +12,7 @@ Please do not open a public issue for security reports. You can expect an initia
12
12
 
13
13
  ## Network and file access
14
14
 
15
- URL mode requests HTML and Markdown over HTTP or HTTPS. Non-public network targets are blocked, including targets reached through DNS and redirects. Each fetch has a deadline and a limit on decoded response bytes. The defaults are 15 seconds and 5 MiB. JavaScript from fetched pages is not executed.
15
+ URL mode requests HTML and Markdown over HTTP or HTTPS. Non-public network targets are blocked, including targets reached through DNS and redirects. Each fetch has a deadline and a limit on decoded response bytes. The defaults are 15 seconds and 5 MiB. In the command line the same deadline also covers parsing and comparison, which run in a worker thread that is stopped when the deadline passes, and the tool then exits with code 2. The library entry point has no such deadline, so a program that compares untrusted documents with it needs a time limit of its own. JavaScript from fetched pages is not executed.
16
16
 
17
17
  The work of pairing blocks is bounded by the product of the two block counts, at most 4 000 000 block pairs. The number of similar block pairs kept for matching is bounded as well. Above either limit the tool stops with exit code 2 and an error message instead of reporting a pass for a comparison it did not complete. The pairing of links inside one block is not separately bounded by default: with the default limits it has no budget of its own, and a block with thousands of links that cannot be resolved against a base URL can take time that grows with the square of the link count. A library caller can set the maxSimilarityWork limit to stop it.
18
18
 
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.28\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.29\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
@@ -7,7 +7,8 @@ import { parseArgs } from 'node:util';
7
7
  import { fileURLToPath } from 'node:url';
8
8
  import { fetchUrl, FetchError, validateUrl } from './fetch.js';
9
9
  import { renderJson, renderText } from './report.js';
10
- import { errorReport, run, RunError } from './run.js';
10
+ import { runWithDeadline } from './deadline.js';
11
+ import { errorReport, RunError } from './run.js';
11
12
  import { maskUrl, redactText } from './normalize.js';
12
13
  import { TOOL_NAME, TOOL_VERSION } from './version.js';
13
14
  export const HELP = `${TOOL_NAME} ${TOOL_VERSION}
@@ -34,7 +35,8 @@ Options:
34
35
  starts with a YAML-looking fenced block; strip removes that leading block.
35
36
  --format text|json Report format (default: text).
36
37
  --output <path> Write the report to a file instead of stdout. Refuses to overwrite an input file.
37
- --timeout-ms <n> Per-fetch timeout in milliseconds (default: 15000).
38
+ --timeout-ms <n> Timeout in milliseconds for each fetch and for the parse-and-compare step
39
+ (default: 15000). When it runs out the exit code is 2.
38
40
  --max-bytes <n> Cap on decoded response bytes per fetch (default: 5242880).
39
41
  --strict Treat warnings as rejecting findings too.
40
42
  --help, -h Show this help.
@@ -345,7 +347,9 @@ export async function main(argv, io = { stdout: (s) => process.stdout.write(s),
345
347
  html = readFileInput(args.htmlFile, base);
346
348
  markdown = readFileInput(args.markdownFile, base);
347
349
  }
348
- report = run(html, markdown, options);
350
+ // The deadline also covers parsing and comparison, which a timer on this thread cannot interrupt, so
351
+ // the step runs in a worker thread that is terminated when --timeout-ms has passed (exit 2).
352
+ report = await runWithDeadline(html, markdown, options, args.timeoutMs);
349
353
  }
350
354
  catch (err) {
351
355
  let message;
@@ -0,0 +1,3 @@
1
+ import { type Report, type RunOptions, type SourceInput } from './run.js';
2
+ /** Runs run(html, markdown, options) in a worker thread and fails with a RunError (exit 2) when it has not finished after timeoutMs. */
3
+ export declare function runWithDeadline(html: SourceInput, markdown: SourceInput, options: RunOptions, timeoutMs: number): Promise<Report>;
@@ -0,0 +1,60 @@
1
+ // Time limit for the parse-and-compare step of the command line. The Markdown and HTML parsers are
2
+ // synchronous, so a timer on the same thread cannot interrupt them. The step therefore runs in a
3
+ // worker thread (src/run-worker.ts) that is terminated at the deadline. The library core does not
4
+ // use this file (see src/core.ts).
5
+ //
6
+ // The deadline starts when the worker reports that its modules are loaded, not when it is spawned:
7
+ // starting a thread and loading the parsers takes about 170 ms, and counting that would make a small
8
+ // --timeout-ms value fail an ordinary local run (QA 1, Q6). A separate, generous start limit covers a
9
+ // worker that never becomes ready.
10
+ import { Worker } from 'node:worker_threads';
11
+ import { RunError } from './run.js';
12
+ /** How long the worker may take to load before the run is given up. Not tied to --timeout-ms. */
13
+ const START_LIMIT_MS = 30_000;
14
+ /** Runs run(html, markdown, options) in a worker thread and fails with a RunError (exit 2) when it has not finished after timeoutMs. */
15
+ export function runWithDeadline(html, markdown, options, timeoutMs) {
16
+ return new Promise((resolve, reject) => {
17
+ const input = { html, markdown, options };
18
+ const worker = new Worker(new URL('./run-worker.js', import.meta.url), { workerData: input });
19
+ let settled = false;
20
+ let timer;
21
+ const finish = (fn) => {
22
+ if (settled)
23
+ return;
24
+ settled = true;
25
+ clearTimeout(startTimer);
26
+ clearTimeout(timer);
27
+ void worker.terminate();
28
+ fn();
29
+ };
30
+ const startTimer = setTimeout(() => {
31
+ finish(() => reject(new RunError(`The comparison worker did not start within ${START_LIMIT_MS} ms.`)));
32
+ }, START_LIMIT_MS);
33
+ worker.on('message', (msg) => {
34
+ if (msg.ready) {
35
+ clearTimeout(startTimer);
36
+ if (!settled) {
37
+ timer = setTimeout(() => {
38
+ finish(() => reject(new RunError(`Timed out after ${timeoutMs} ms while parsing and comparing the two documents (--timeout-ms covers this step as well as each fetch).`)));
39
+ }, timeoutMs);
40
+ }
41
+ return;
42
+ }
43
+ const out = msg;
44
+ finish(() => {
45
+ if (out.ok)
46
+ resolve(out.report);
47
+ else if (out.runError)
48
+ reject(new RunError(out.message, out.value));
49
+ else {
50
+ const e = new Error(out.message);
51
+ if (out.stack !== undefined)
52
+ e.stack = out.stack;
53
+ reject(e);
54
+ }
55
+ });
56
+ });
57
+ worker.once('error', (err) => finish(() => reject(err)));
58
+ worker.once('exit', (code) => finish(() => reject(new Error(`The comparison worker stopped without a result (exit ${code}).`))));
59
+ });
60
+ }
package/dist/src/fetch.js CHANGED
@@ -88,13 +88,18 @@ function decompressor(encoding) {
88
88
  }
89
89
  /**
90
90
  * One wall-clock deadline for a whole fetchUrl call: DNS, connect, headers, body, decompression and every
91
- * redirect hop. When it fires, the active request is destroyed and the pending step rejects.
91
+ * redirect hop. When it fires, the active request, its response and its decompression stream are destroyed
92
+ * and the pending step rejects.
92
93
  */
93
94
  class Deadline {
94
95
  timer;
95
96
  expired = false;
96
97
  active = null;
97
98
  waiters = new Set();
99
+ // Teardown callbacks of the response streams of the active hop. Destroying only the request leaves the
100
+ // decompression stream decoding what it already received (a gzip bomb of about 64 KiB on the wire decodes to
101
+ // 64 MiB, a brotli one to hundreds of MiB), so the streams are destroyed as well.
102
+ teardowns = new Set();
98
103
  error;
99
104
  constructor(url, timeoutMs) {
100
105
  this.error = new FetchError('timeout', url, `Timed out after ${timeoutMs} ms (whole fetch including DNS, redirects and body).`);
@@ -104,10 +109,25 @@ class Deadline {
104
109
  this.expired = true;
105
110
  if (this.active)
106
111
  this.active.destroy(this.error);
112
+ for (const t of this.teardowns)
113
+ t();
114
+ this.teardowns.clear();
107
115
  for (const w of this.waiters)
108
116
  w(this.error);
109
117
  this.waiters.clear();
110
118
  }
119
+ /** Registers a callback that destroys the response streams of the active hop when the deadline fires.
120
+ * Returns a function that removes it again. */
121
+ onFire(teardown) {
122
+ if (this.expired) {
123
+ teardown();
124
+ return () => { };
125
+ }
126
+ this.teardowns.add(teardown);
127
+ return () => {
128
+ this.teardowns.delete(teardown);
129
+ };
130
+ }
111
131
  attach(req) {
112
132
  this.active = req;
113
133
  if (this.expired)
@@ -177,15 +197,30 @@ function requestOnce(url, address, options, deadline) {
177
197
  reject(new FetchError('protocol', url.href, err.message));
178
198
  return;
179
199
  }
200
+ // Destroys the decompression stream and the response and detaches the pipe between them, so nothing decodes
201
+ // or reads on after the fetch has failed. No error is passed to destroy(), so neither stream emits one.
202
+ const teardown = () => {
203
+ if (dec) {
204
+ res.unpipe(dec);
205
+ dec.destroy();
206
+ }
207
+ res.destroy();
208
+ };
209
+ const unregister = deadline.onFire(teardown);
180
210
  if (dec) {
181
211
  stream = res.pipe(dec);
182
212
  dec.on('error', (err) => finish(new FetchError('protocol', url.href, `Decompression failed: ${err.message}`)));
213
+ // A response that breaks off mid-body is a network failure; without this listener the error of the
214
+ // source stream of a pipe is not handled by anything.
215
+ res.on('error', (err) => finish(new FetchError('network', url.href, err.message)));
183
216
  }
184
217
  const finish = (err) => {
185
218
  if (done)
186
219
  return;
187
220
  done = true;
221
+ unregister();
188
222
  if (err) {
223
+ teardown();
189
224
  req.destroy();
190
225
  reject(err);
191
226
  }
@@ -11,8 +11,8 @@ 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
14
+ /** The user-supplied value the message names (here, --selector), capped the way the hosted validator's cut()
15
+ * (src/worker.ts in turva-worker) caps a reflected value: in its own field, not only interpolated into the sentence, and bounded so an
16
16
  * arbitrarily long selector cannot make the error text arbitrarily long (V10-P3-01, found by an outside
17
17
  * review 2026-09-28). Report rendering still masks every string, value included, through redactText. */
18
18
  value?: string;
package/dist/src/html.js CHANGED
@@ -5,8 +5,8 @@ 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
8
+ /** The user-supplied value the message names (here, --selector), capped the way the hosted validator's cut()
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
10
10
  * arbitrarily long selector cannot make the error text arbitrarily long (V10-P3-01, found by an outside
11
11
  * review 2026-09-28). Report rendering still masks every string, value included, through redactText. */
12
12
  value;
@@ -16,7 +16,7 @@ export class HtmlExtractError extends Error {
16
16
  this.value = capValue(value);
17
17
  }
18
18
  }
19
- /** Caps a value that a message reflects back to the caller, the same length worker.js's own cut() uses, and
19
+ /** Caps a value that a message reflects back to the caller, the same length the hosted validator's cut() (src/worker.ts in turva-worker) uses, and
20
20
  * drops a trailing lone high surrogate a plain slice can leave behind. */
21
21
  function capValue(s, n = 120) {
22
22
  const cut = s.slice(0, n);
@@ -140,6 +140,10 @@ export function isPublicIPv6(ip) {
140
140
  return false; // ::1
141
141
  if (allZeroTo(5) && g5 === 0xffff)
142
142
  return isPublicIPv4(v4FromGroups(g6, g7)); // ::ffff:a.b.c.d
143
+ // ::ffff:0:a.b.c.d is the IPv4-translated range (RFC 2765 SIIT, ::ffff:0:0:0/96); like the mapped form it carries an IPv4
144
+ // address in the last 32 bits, so that address decides.
145
+ if (g0 === 0 && g1 === 0 && g2 === 0 && g3 === 0 && g4 === 0xffff && g5 === 0)
146
+ return isPublicIPv4(v4FromGroups(g6, g7));
143
147
  if (allZeroTo(6))
144
148
  return isPublicIPv4(v4FromGroups(g6, g7)); // ::a.b.c.d (deprecated compatible)
145
149
  if (g0 === 0x64 && g1 === 0xff9b && g2 === 0 && g3 === 0 && g4 === 0 && g5 === 0)
@@ -8,7 +8,7 @@ export declare function looseNormalize(text: string): string;
8
8
  export declare function codeWhitespaceKey(code: string): string;
9
9
  /** Code content: CRLF and CR line endings become LF and every trailing newline is removed; other whitespace is kept. */
10
10
  export declare function normalizeCode(code: string): string;
11
- /** Removes ANSI escape sequences and other C0 controls from a value that may come from a compared page or a raw
11
+ /** Removes ANSI escape sequences, other C0 and C1 controls and the Unicode bidi controls from a value that may come from a compared page or a raw
12
12
  * argument, so a plain --format text report cannot replay them at the terminal (0.2.16, found by an outside
13
13
  * review 2026-09-28). */
14
14
  export declare function stripControlChars(text: string): string;
@@ -42,12 +42,15 @@ export function codeWhitespaceKey(code) {
42
42
  export function normalizeCode(code) {
43
43
  return code.replace(/\r\n?/g, '\n').replace(/\n+$/, '');
44
44
  }
45
- // Terminal control characters (ANSI escape sequences and other C0 controls) reach a text report unescaped if a
45
+ // Terminal control characters (ANSI escape sequences, C0 and C1 controls) and the Unicode bidi controls reach a text report unescaped if a
46
46
  // compared page or an argument carries one, while --format json is already safe because JSON.stringify escapes
47
47
  // every control character. Tab, newline and carriage return are kept: they are ordinary formatting, and by the
48
48
  // time most report text reaches this point strictNormalize has already collapsed them to a single space anyway.
49
- const CONTROL_CHARS = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g;
50
- /** Removes ANSI escape sequences and other C0 controls from a value that may come from a compared page or a raw
49
+ // C1 controls (U+0080 to U+009F) include the single-byte CSI (U+009B), which some terminals read as an escape. The bidi
50
+ // controls (U+202A to U+202E and U+2066 to U+2069) reorder the text a reader sees, so a quoted excerpt could read
51
+ // differently in a report than in the page. Both ranges match the hosted validator's stripControls(stripBidi()).
52
+ const CONTROL_CHARS = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f\u202A-\u202E\u2066-\u2069]/g;
53
+ /** Removes ANSI escape sequences, other C0 and C1 controls and the Unicode bidi controls from a value that may come from a compared page or a raw
51
54
  * argument, so a plain --format text report cannot replay them at the terminal (0.2.16, found by an outside
52
55
  * review 2026-09-28). */
53
56
  export function stripControlChars(text) {
@@ -462,8 +465,15 @@ export function maskHref(href) {
462
465
  const u = new URL(href);
463
466
  u.username = '';
464
467
  u.password = '';
465
- for (const key of Array.from(u.searchParams.keys()))
466
- u.searchParams.set(key, '***');
468
+ // One pass (Tek-560 in the hosted validator): a Set keeps the first-seen key order and merges duplicates, and the
469
+ // masked query is built once with append. Calling searchParams.set for each key re-serializes the whole query
470
+ // every time, which is quadratic in the number of keys (5 000 keys took 2.1 s, 20 000 took 35 s). An empty
471
+ // query is left as it is, so "?" stays "?".
472
+ const maskedQuery = new URLSearchParams();
473
+ for (const key of new Set(u.searchParams.keys()))
474
+ maskedQuery.append(key, '***');
475
+ if (maskedQuery.toString() !== '')
476
+ u.search = maskedQuery.toString();
467
477
  u.hash = '';
468
478
  return u.href;
469
479
  }
@@ -0,0 +1,22 @@
1
+ import { run, type RunOptions, type SourceInput } from './run.js';
2
+ export interface WorkerInput {
3
+ html: SourceInput;
4
+ markdown: SourceInput;
5
+ options: RunOptions;
6
+ }
7
+ export type WorkerOutput = {
8
+ ok: true;
9
+ report: ReturnType<typeof run>;
10
+ } | {
11
+ ok: false;
12
+ runError: boolean;
13
+ message: string;
14
+ value?: string;
15
+ stack?: string;
16
+ };
17
+ /** The first message says the modules are loaded and the deadline may start; the second is the result. */
18
+ export type WorkerMessage = {
19
+ ready: true;
20
+ } | (WorkerOutput & {
21
+ ready?: undefined;
22
+ });
@@ -0,0 +1,22 @@
1
+ // Worker thread entry used by the command line only (src/deadline.ts starts it). It runs the same
2
+ // run() the library exports, so a hostile document that keeps the parser busy can be stopped by
3
+ // terminating this thread at the deadline. Nothing in the library core imports this file or
4
+ // node:worker_threads; test/core.test.ts walks the core's import graph to keep it that way.
5
+ import { parentPort, workerData } from 'node:worker_threads';
6
+ import { run, RunError } from './run.js';
7
+ function reply(out) {
8
+ parentPort.postMessage(out);
9
+ }
10
+ // Static imports are evaluated before this line, so the parsers are loaded when the main thread
11
+ // starts the deadline. run() begins right after, in the same turn.
12
+ reply({ ready: true });
13
+ try {
14
+ const input = workerData;
15
+ reply({ ok: true, report: run(input.html, input.markdown, input.options) });
16
+ }
17
+ catch (err) {
18
+ if (err instanceof RunError)
19
+ reply({ ok: false, runError: true, message: err.message, value: err.value });
20
+ else
21
+ reply({ ok: false, runError: false, message: err?.message ?? String(err), stack: err?.stack });
22
+ }
package/dist/src/run.d.ts CHANGED
@@ -70,7 +70,7 @@ export interface Report {
70
70
  /** Present when the comparison could not be completed reliably. */
71
71
  error?: string;
72
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). */
73
+ * the message sentence (V10-P3-01, the same split the hosted validator's diagnostics in src/worker.ts of turva-worker already use). */
74
74
  errorValue?: string;
75
75
  };
76
76
  findings: Finding[];
@@ -1,2 +1,2 @@
1
1
  export declare const TOOL_NAME = "markdown-parity-check";
2
- export declare const TOOL_VERSION = "0.2.28";
2
+ export declare const TOOL_VERSION = "0.2.29";
@@ -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.28';
5
+ export const TOOL_VERSION = '0.2.29';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-parity-check",
3
- "version": "0.2.28",
3
+ "version": "0.2.29",
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",