markdown-parity-check 0.2.42 → 0.2.43
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 +33 -19
- package/dist/src/cli.d.ts +1 -1
- package/dist/src/cli.js +5 -0
- package/dist/src/fetch.js +17 -1
- package/dist/src/html.js +40 -9
- package/dist/src/markdown.js +9 -2
- package/dist/src/normalize.d.ts +20 -3
- package/dist/src/normalize.js +183 -23
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ Exit code 0 means the implemented checks found nothing to reject. It does not pr
|
|
|
63
63
|
| `--markdown-url URL` | Request the Markdown from a separate address. Needs `--url`. |
|
|
64
64
|
| `--html-file PATH --markdown-file PATH` | Compare two local files instead. |
|
|
65
65
|
| `--base-url URL` | Resolve relative links in local files. Local-file mode only. |
|
|
66
|
-
| `--selector CSS` | Choose the HTML content container. |
|
|
66
|
+
| `--selector CSS` | Choose the HTML content container. Several matches give a note and the first in document order is used. No match is an error and ends the run with exit code 2. |
|
|
67
67
|
| `--html-profile generic` or `--html-profile starlight` | Use the generic HTML rules, which is the default, or the Starlight rules, which also compare inactive tab panels and keep Expressive Code line breaks. |
|
|
68
68
|
| `--front-matter keep` or `--front-matter strip` | Keep Markdown front matter, which is the default, or remove it before the comparison. |
|
|
69
69
|
| `--format text` or `--format json` | Print a readable report, which is the default, or a structured one. |
|
|
@@ -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.
|
|
81
|
+
This is the text report for the matching fixture pair in this repository, run with version 0.2.43 on 2026-11-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.
|
|
84
|
+
markdown-parity-check 0.2.43 (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)
|
|
@@ -103,7 +103,7 @@ Without `--selector`, the tool looks for a visible `main`, then a visible `artic
|
|
|
103
103
|
|
|
104
104
|
- A candidate is visible when neither it nor an ancestor is hidden, in a template or inside one of the left-out subtrees listed below. An `article` inside a `nav` is therefore not used.
|
|
105
105
|
- A `form` is the one exception, so a `main` inside a `form` that has no left-out role is still used, however far up the form sits.
|
|
106
|
-
- If none of them exists, the page body is used and the report warns that page chrome may leak in.
|
|
106
|
+
- If none of them exists, the page body is used and the report warns that page chrome may leak in. A source with no `<body>` element written in it that has none of them ends with the error `Document has no <body> element.` and exit code 2.
|
|
107
107
|
- Two visible elements of the same kind that do not contain one another also give a warning, because only the first is compared.
|
|
108
108
|
|
|
109
109
|
Front matter is kept by default and compared as content. If the HTML does not carry the same text, that alone fails the comparison. The tool also warns when the Markdown starts with a block that looks like YAML front matter, and `--front-matter strip` removes it.
|
|
@@ -114,13 +114,13 @@ Headings, paragraphs, list items, tables, code blocks and links are compared blo
|
|
|
114
114
|
|
|
115
115
|
Content that is hidden or sits inside a left-out element is left out on both sides. This also holds when the raw HTML wrapper, such as `<div hidden>` or `<nav>`, is opened in one Markdown block and closed in a later one. A table caption counts as a paragraph before the table.
|
|
116
116
|
|
|
117
|
-
Hidden means the `hidden` attribute, `aria-hidden="true"` and a `template` element, whose content a browser never renders. An element with `aria-hidden="true"` counts as hidden although a sighted reader still sees it, so text that only the HTML carries inside such an element is not reported as missing from the Markdown. A style that hides an element, such as `display: none`, is not evaluated, because CSS is not read. In the Markdown, an HTML comment and an unused link reference definition, which is one that no link uses, are not content and give no finding, not even with `--strict`. A definition that a link uses is compared through that link.
|
|
117
|
+
Hidden means the `hidden` attribute, `aria-hidden="true"` and a `template` element, whose content a browser never renders. An element with `aria-hidden="true"` counts as hidden although a sighted reader still sees it, so text that only the HTML carries inside such an element is not reported as missing from the Markdown. The `starlight` profile compares the title of a Starlight aside although it carries `aria-hidden="true"`, as [docs/starlight.md](https://github.com/erekola/markdown-parity-check/blob/main/docs/starlight.md) describes. A style that hides an element, such as `display: none`, is not evaluated, because CSS is not read. In the Markdown, an HTML comment and an unused link reference definition, which is one that no link uses, are not content and give no finding, not even with `--strict`. A definition that a link uses is compared through that link.
|
|
118
118
|
|
|
119
119
|
- Errors: missing and added blocks, a change in text or numbers, a changed table or link, and a list item that shows another number or a different checked or unchecked state.
|
|
120
|
-
- Warnings: a checkbox that is present on one side only, a difference in order and a difference in heading level, case, punctuation, list kind or nesting level. A difference in order is also reported for a block that moved and changed only in case, punctuation or typographic characters. A block that moved and also changed in its words or numbers gets the finding for that change and no order finding. A changed accent mark, vowel sign, symbol or emoji is a change in text and not in punctuation, so it is an error. A swapped symbol is an error also when a reader sees the same meaning. Examples are an ASCII arrow made of a hyphen and a greater-than sign against an arrow character, or a dropped trademark sign. An invisible variation selector alone is not. Each footnote in the Markdown is a warning, because footnotes are not compared. These are the main cases, and the `code` of each finding names the exact rule. A missing or extra copy of a repeated block is reported as a missing or added block, which is an error.
|
|
121
|
-
- Information:
|
|
120
|
+
- Warnings: a relative link target that differs in text while no `--base-url` is known, so the two forms cannot be confirmed equal or different, which fails a `--strict` run, a raw HTML block in the Markdown whose text could not be parsed into blocks and so was not compared, a checkbox that is present on one side only, a difference in order and a difference in heading level, case, punctuation, list kind or nesting level. A difference in order is also reported for a block that moved and changed only in case, punctuation or typographic characters. A block that moved and also changed in its words or numbers gets the finding for that change and no order finding. A changed accent mark, vowel sign, symbol or emoji is a change in text and not in punctuation, so it is an error. A swapped symbol is an error also when a reader sees the same meaning. Examples are an ASCII arrow made of a hyphen and a greater-than sign against an arrow character, or a dropped trademark sign. An invisible variation selector alone is not. Each footnote in the Markdown is a warning, because footnotes are not compared. These are the main cases, and the `code` of each finding names the exact rule. A missing or extra copy of a repeated block is reported as a missing or added block, which is an error.
|
|
121
|
+
- Information: a skipped comparison of a reversed list or of a table with spans, a raw HTML block that was parsed, and front matter that was stripped. None of them fails a check, not even with `--strict`.
|
|
122
122
|
|
|
123
|
-
The cell-by-cell comparison of a table is skipped when one of its cells has a rowspan or colspan above 1, a rowspan of 0, or a value that is empty or does not begin with a number. The number is read
|
|
123
|
+
The cell-by-cell comparison of a table is skipped when one of its cells has a rowspan or colspan above 1, a rowspan of 0, or a value that is empty or does not begin with a number. The number is read with `parseInt`, so leading white space, a no-break space included, and a plus or minus sign are accepted, `2abc` counts as 2, and a negative value is not above 1. A colspan of 0 and a rowspan or colspan of 1 do not trigger it. The links and the caption of such a table are still compared. The numbering of a reversed list is not compared either.
|
|
124
124
|
|
|
125
125
|
### Content that is left out
|
|
126
126
|
|
|
@@ -128,7 +128,7 @@ Some content is left out even when it sits inside the main content, in code bloc
|
|
|
128
128
|
|
|
129
129
|
- `form`, `button`, `input`, `select`, `textarea`, `dialog`, `iframe`, `svg`, `canvas`, `object`, `embed` and `map`.
|
|
130
130
|
- `nav`, `script`, `style`, `noscript` and `template`.
|
|
131
|
-
- Any element with the role `navigation`, `banner`, `contentinfo`, `complementary`, `search`, `menu`, `menubar` or `dialog`.
|
|
131
|
+
- Any element with the role `navigation`, `banner`, `contentinfo`, `complementary`, `search`, `menu`, `menubar` or `dialog`. The `role` attribute is read as a list of tokens, and the first token that names a role of WAI-ARIA 1.2 decides, so `role="navigation foo"` and `role="foo navigation"` count, and so does `role="doc-toc navigation"`, because `doc-toc` is not in that list. A page whose whole content sits in such an element ends with the error `HTML main content is empty` and exit code 2. The `[role=main]` candidate for the content container stays an exact match.
|
|
132
132
|
- A `header` or `footer` that sits directly under `body` or `html`, unless it is the content container itself.
|
|
133
133
|
|
|
134
134
|
The `starlight` profile keeps an iframe that has a source and a title, as a link. The same list applies to inline raw HTML in the Markdown and to the checkbox of a task list item, which must belong to the item itself.
|
|
@@ -141,7 +141,7 @@ A `<br>` in a code block is a line break. A code block that differs only in whit
|
|
|
141
141
|
|
|
142
142
|
### Delivery in URL mode
|
|
143
143
|
|
|
144
|
-
In URL mode the Markdown response is checked first. An HTTP error or an HTML page in place of Markdown fails the check, and nothing is compared. A Markdown response labelled `text/plain` is a warning, and any other content type than `text/markdown` or `text/x-markdown` is an error. A comment, an XML declaration or another declaration before the doctype does not hide an HTML page from this check. If the HTML request itself returns an HTTP error, the run ends with exit code 2.
|
|
144
|
+
In URL mode the Markdown response is checked first. An HTTP error or an HTML page in place of Markdown fails the check, and nothing is compared. A Markdown response labelled `text/plain` is a warning, and any other content type than `text/markdown` or `text/x-markdown` is an error. A comment, an XML declaration or another declaration before the doctype does not hide an HTML page from this check. Only a response that starts with `<!doctype html` or `<html` counts as an HTML page here. A fragment that starts with `<body>` or another tag is compared as Markdown, and its raw HTML gives an information finding. If the HTML request itself returns an HTTP error, the run ends with exit code 2.
|
|
145
145
|
|
|
146
146
|
A response whose Content-Type header names `text/html` or `application/xhtml+xml` is decoded by its byte order mark first, then by the charset of that header, then by a meta charset declaration in its first 1024 bytes. It is decoded as UTF-8 when none of them names a known encoding.
|
|
147
147
|
|
|
@@ -151,9 +151,23 @@ 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
|
|
154
|
+
The masking is a display safeguard. It reads text by its shape and not by its meaning, so text that reads as user information is masked even when it is prose: `Meet 10:30@venue ok` is shown as `Meet *** ok`, `std::vector@x` as `std:***`, and a paragraph that starts with `// TODO:fix mail me@x.org` is shown as `//x.org`, because a `//` starts a network-path reference. It 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. The paragraphs below say what is masked and what is shown.
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
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`.
|
|
157
|
+
|
|
158
|
+
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.
|
|
159
|
+
|
|
160
|
+
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. Masked too: 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. 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`, is shown as `***`. When the text before the `@` of a non-special scheme word holds a number sign, a question mark, a space or a backslash, as in `user:pass#word@host.example/p`, the target is shown as `user:***`. One-letter words, drive letters as in `C:\dir\file@2x.png`, are not read this way. Each of these shapes is masked after a leading Unicode space or a NUL character too.
|
|
161
|
+
|
|
162
|
+
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. The `Location` header is read as UTF-8, as a browser reads it, so an ideographic space, a no-break space or U+FFFD that arrives as bytes at its start counts as a leading character, and the shapes above are masked behind it. A `--url` of these shapes, as in `http://host.example:8080\erik:password@other.example/p`, is masked the same way. The URL parser reads it 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`.
|
|
163
|
+
|
|
164
|
+
Report text is read the same way. A word of an excerpt, a message or a link text, which is the text between white space, angle brackets and double quotes, is shown as a link target of the same shape would be when the text before its last `@` holds a colon, a backslash, a question mark or a number sign, where the colon counts after the scheme word when there is one. So `https://CORP\erik:password@host.example/x` is shown as `https://***/`, and `DOMAIN\erik:password@host.example/p` and `:password@host.example/x` are shown as `***`. A word that the rules above for a scheme or a leading `//` already mask keeps the result of those rules, such as `user:***@host.example/p`. An error that repeats a value, such as the value of `--base-url`, `--timeout-ms` or `--html-file`, reads it as a link target first, so `ftp://corp.example\erik:password@host.example/` is shown as `ftp://***`. For a rejected `--selector` that holds an `@`, the message of the selector parser is never quoted, and the value that the error names is read in the same way, or shown as `***@` and the text after its last `@`. In report text the word in front of the colon keeps the case it was written in, so `Re:Re:@work` is shown as `Re:***`, where a link target shows a scheme word in lower case.
|
|
165
|
+
|
|
166
|
+
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. In Markdown a backslash before a punctuation mark stands for the mark, so `\/user:password@host.example` is that relative path too. A plain space, a no-break space or any other Unicode space right after the colon of the user information, such as U+3000, U+2003 or U+202F, and a password of digits only that is followed by white space, are read as text and shown. A tab right after the colon belongs to the user information and is masked in a link target, a message and an option value. In an excerpt it is shown, because the text of a block has turned the tab into a space by then. In running text a password that holds white space is masked only after `://` or after a leading `//`, with no backslash domain before the user name. Elsewhere the whole text is shown as written, so `user:pass word@host.example/p`, `user:password#a b@host.example/p`, `user:password?a b@host.example/p` and `user:password# x@host.example/p` in a paragraph are shown whole. A link target is read as a whole and has no such limit.
|
|
167
|
+
|
|
168
|
+
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`.
|
|
169
|
+
|
|
170
|
+
A link target longer than 8192 UTF-16 code units 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
171
|
|
|
158
172
|
## Command line and hosted page
|
|
159
173
|
|
|
@@ -209,19 +223,19 @@ console.log(report.summary.result, report.summary.exitCode);
|
|
|
209
223
|
console.log(renderJson(report));
|
|
210
224
|
```
|
|
211
225
|
|
|
212
|
-
`run(html, markdown, options)` returns the `Report` object. `renderJson(report)`
|
|
226
|
+
`run(html, markdown, options)` returns the `Report` object. `renderJson(report)` returns the string that `--format json` prints, with URL query values, fragments and credentials masked. The object `run` returns is not masked. A completed run has the result `pass` with exit code 0 or `fail` with exit code 1. When the comparison cannot finish, for example because the content is empty or a limit is exceeded, `run` throws a `RunError`. `errorReport` builds the error report the command prints in that case.
|
|
213
227
|
|
|
214
228
|
The options type is `RunOptions`. It takes `selector`, `frontMatter`, `strict`, `mode` and `htmlProfile`, which is `generic` or `starlight`. The Starlight rules are described in [docs/starlight.md](https://github.com/erekola/markdown-parity-check/blob/main/docs/starlight.md). The report records `mode` as `url` or `offline`, and it does not switch any check on or off.
|
|
215
229
|
|
|
216
230
|
When the Markdown source has `kind: 'url'` in its `meta`, the delivery check runs first and reads the HTTP `status` and `contentType` from that `meta`.
|
|
217
231
|
|
|
218
|
-
A host with a smaller CPU or memory budget can pass lower `limits`, typed as `RunLimits`: `maxAlignmentPairs`, `maxSimilarityCandidates`, `maxSimilarityWork` and `maxNestingDepth`. The nesting limit also applies to raw HTML blocks inside the Markdown.
|
|
232
|
+
A host with a smaller CPU or memory budget can pass lower `limits`, typed as `RunLimits`: `maxAlignmentPairs`, `maxSimilarityCandidates`, `maxSimilarityWork` and `maxNestingDepth`. The nesting limit also applies to raw HTML blocks inside the Markdown. A limit that is zero, negative or NaN throws a `TypeError` before the comparison starts, and a valid limit that is exceeded is a `RunError`.
|
|
219
233
|
|
|
220
234
|
Set `maxSimilarityWork` when the library compares untrusted documents. With the default limits one worst case at the full 4 000 000 block pairs (100 HTML blocks of 870 distinct words against 40 000 Markdown blocks of one word each) took tens of seconds in hand timings on development machines. In the same case, a value of 2 000 000 made the pairing step stop, and the whole call, parsing included, took about a second.
|
|
221
235
|
|
|
222
236
|
The test suite runs the bounded case and asserts no time. When a limit is exceeded, `run` throws a `RunError` whose message names the limit, and the command line reports it with exit code 2.
|
|
223
237
|
|
|
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
|
|
238
|
+
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 UTF-16 code units is a `RunError`, as described under the limits of the method.
|
|
225
239
|
|
|
226
240
|
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
241
|
|
|
@@ -237,13 +251,13 @@ The JSON report is the `Report` type. Its top-level fields are:
|
|
|
237
251
|
| `toolVersion` | The release that produced the report. |
|
|
238
252
|
| `generatedAt` | The time the report was made, as an ISO 8601 timestamp in UTC. |
|
|
239
253
|
| `mode` | `url` or `offline`. |
|
|
240
|
-
| `sources` | The metadata of the HTML and the Markdown input. |
|
|
254
|
+
| `sources` | The metadata of the HTML and the Markdown input. For a local file, `bytes` is the size of its text without a byte order mark, counted as UTF-8, and not the size of the file on disk. |
|
|
241
255
|
| `extraction` | How each side was extracted. It is `null` in an error report and in a result that failed at the delivery check, because no extraction result is reported then. |
|
|
242
256
|
| `summary` | `result`, which is `pass`, `fail` or `error`, then `strict`, the counts `errors`, `warnings` and `infos`, `coverage`, which is `null` when nothing was compared, `exitCode` and, when `result` is `error`, `error` and sometimes `errorValue`. |
|
|
243
257
|
| `findings` | A list of `Finding` objects, each with `code`, `severity`, `direction` and `message`, and where they apply the `html` and `markdown` locations and the `before` and `after` text. |
|
|
244
258
|
| `limitations` | The fixed list of what the check does not cover. |
|
|
245
259
|
|
|
246
|
-
|
|
260
|
+
After the arguments fail validation, the command builds an error report for the argument error from the raw arguments. It takes `mode` from the presence of `--url` and `summary.strict` from the presence of `--strict` in the command line, and it prints the JSON to standard output only when the raw arguments ask for JSON. A command line with neither is recorded as `offline` and not strict, and so is one that gives `--markdown-url` without `--url`.
|
|
247
261
|
|
|
248
262
|
## Development
|
|
249
263
|
|
|
@@ -272,12 +286,12 @@ Only after that check does it create the GitHub release with the verified tarbal
|
|
|
272
286
|
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
287
|
|
|
274
288
|
```sh
|
|
275
|
-
mkdir verify-mpc && cd verify-mpc && npm init -y && npm install markdown-parity-check@0.2.
|
|
289
|
+
mkdir verify-mpc && cd verify-mpc && npm init -y && npm install markdown-parity-check@0.2.43 --ignore-scripts && npm audit signatures
|
|
276
290
|
```
|
|
277
291
|
|
|
278
292
|
`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
293
|
|
|
280
|
-
Tag `v0.2.
|
|
294
|
+
Tag `v0.2.43` must point at that same commit, and `gh api repos/erekola/markdown-parity-check/commits/v0.2.43 --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
295
|
|
|
282
296
|
## Security
|
|
283
297
|
|
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.
|
|
3
|
+
export declare const HELP = "markdown-parity-check 0.2.43\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
|
@@ -109,6 +109,11 @@ function oneLineText(value) {
|
|
|
109
109
|
return value.replace(/[\r\n]/g, (c) => (c === '\n' ? '\\n' : '\\r'));
|
|
110
110
|
}
|
|
111
111
|
function maskOptionRaw(value) {
|
|
112
|
+
// The reading a link target gets comes first (0.2.43, PF2 and PF4 of the second outside masking run): maskUrl alone
|
|
113
|
+
// showed ftp://corp.example\erik:secret@example.com/ as ftp://corp.example/erik:secret@example.com/.
|
|
114
|
+
const moved = movedUserinfoMask(value);
|
|
115
|
+
if (moved !== null)
|
|
116
|
+
return moved;
|
|
112
117
|
const plain = value.replace(/[\t\n\r]/g, '');
|
|
113
118
|
let hasHost = false;
|
|
114
119
|
try {
|
package/dist/src/fetch.js
CHANGED
|
@@ -372,6 +372,22 @@ function requestOnce(url, address, options, deadline) {
|
|
|
372
372
|
});
|
|
373
373
|
}
|
|
374
374
|
const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
|
|
375
|
+
/**
|
|
376
|
+
* The text of a Location header. Node hands a header over as the bytes read as latin1, one code unit per byte, but the
|
|
377
|
+
* URL standard reads the value of Location as UTF-8, as a browser does. Without this, the three bytes of U+3000 at the
|
|
378
|
+
* start of a Location stood as three Latin-1 characters that no edge trimming knows, so a followed address that held
|
|
379
|
+
* user information after them was shown whole (0.2.43, PU1 of the second outside masking run), and a path with
|
|
380
|
+
* non-ASCII characters was followed double encoded. A value that holds a code unit above 0xFF is already text and
|
|
381
|
+
* stays; bytes that are not valid UTF-8 become U+FFFD, as the standard decodes them.
|
|
382
|
+
*/
|
|
383
|
+
function locationText(value) {
|
|
384
|
+
if (value === undefined)
|
|
385
|
+
return value;
|
|
386
|
+
for (let i = 0; i < value.length; i++)
|
|
387
|
+
if (value.charCodeAt(i) > 0xff)
|
|
388
|
+
return value;
|
|
389
|
+
return Buffer.from(value, 'latin1').toString('utf8');
|
|
390
|
+
}
|
|
375
391
|
/**
|
|
376
392
|
* Fetches one URL with the given Accept header, following at most maxRedirects redirects. Every hop is
|
|
377
393
|
* validated by the address policy. Returns the decoded body; the raw response is not stored.
|
|
@@ -421,7 +437,7 @@ async function fetchWithDeadline(input, options, maxRedirects, deadline) {
|
|
|
421
437
|
throw err;
|
|
422
438
|
}
|
|
423
439
|
if (REDIRECT_STATUSES.has(res.status)) {
|
|
424
|
-
const loc = res.headers['location'];
|
|
440
|
+
const loc = locationText(res.headers['location']);
|
|
425
441
|
// Both name the address after a hiding hop as shown, not as resolved (N1 of the eighth check).
|
|
426
442
|
if (!loc)
|
|
427
443
|
throw new FetchError('protocol', shown === null ? url.href : shown, `HTTP ${res.status} without a Location header.`);
|
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, markBaseMaskedLinks, normalizeCode, redactText, resolveHref, shownField, shownNormalize, stripControlChars, strictNormalize } from './normalize.js';
|
|
6
|
+
import { extractNumbers, looseNormalize, markBaseMaskedLinks, movedUserinfoMask, 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
|
|
@@ -44,13 +44,37 @@ export function nestingDepth(node) {
|
|
|
44
44
|
}
|
|
45
45
|
const SKIP_TAGS = new Set(['script', 'style', 'noscript', 'template', 'nav', 'iframe', 'svg', 'canvas', 'object', 'embed', 'map', 'form', 'button', 'input', 'select', 'textarea', 'dialog']);
|
|
46
46
|
const SKIP_ROLES = new Set(['navigation', 'banner', 'contentinfo', 'complementary', 'search', 'menu', 'menubar', 'dialog']);
|
|
47
|
+
// The roles of WAI-ARIA 1.2 that a page can name. The role attribute is a list of tokens, and the first one that is
|
|
48
|
+
// a known role is the role of the element; a token the list does not know is a fallback that is passed over.
|
|
49
|
+
const KNOWN_ROLES = new Set([
|
|
50
|
+
'alert', 'alertdialog', 'application', 'article', 'banner', 'blockquote', 'button', 'caption', 'cell', 'checkbox', 'code', 'columnheader', 'combobox',
|
|
51
|
+
'complementary', 'contentinfo', 'definition', 'deletion', 'dialog', 'directory', 'document', 'emphasis', 'feed', 'figure', 'form', 'generic', 'grid',
|
|
52
|
+
'gridcell', 'group', 'heading', 'img', 'insertion', 'link', 'list', 'listbox', 'listitem', 'log', 'main', 'marquee', 'math', 'menu', 'menubar',
|
|
53
|
+
'menuitem', 'menuitemcheckbox', 'menuitemradio', 'meter', 'navigation', 'none', 'note', 'option', 'paragraph', 'presentation', 'progressbar', 'radio',
|
|
54
|
+
'radiogroup', 'region', 'row', 'rowgroup', 'rowheader', 'scrollbar', 'search', 'searchbox', 'separator', 'slider', 'spinbutton', 'status', 'strong',
|
|
55
|
+
'subscript', 'superscript', 'switch', 'tab', 'table', 'tablist', 'tabpanel', 'term', 'textbox', 'time', 'timer', 'toolbar', 'tooltip', 'tree', 'treegrid',
|
|
56
|
+
'treeitem',
|
|
57
|
+
]);
|
|
58
|
+
/** Whether the value of a role attribute names a left-out role: the first token that is a known role, read in
|
|
59
|
+
* lower case after the ASCII white space around the tokens, is one of SKIP_ROLES (0.2.43, K2-F3). Up to 0.2.42 the whole
|
|
60
|
+
* value was compared, so role="navigation foo" and role=" navigation " were compared as content. */
|
|
61
|
+
function hasSkippedRole(role) {
|
|
62
|
+
if (role === undefined)
|
|
63
|
+
return false;
|
|
64
|
+
for (const token of role.split(/[ \t\n\f\r]+/)) {
|
|
65
|
+
const name = token.toLowerCase();
|
|
66
|
+
if (KNOWN_ROLES.has(name))
|
|
67
|
+
return SKIP_ROLES.has(name);
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
47
71
|
/** Whether an opening tag starts a subtree this extraction leaves out: the tag and role lists of isSkipped. The
|
|
48
72
|
* Markdown side asks it for inline raw HTML, so a button or a script in a Markdown paragraph is left out the way
|
|
49
73
|
* it is in an HTML paragraph (0.2.22, found by an outside review 2026-10-02). */
|
|
50
74
|
export function opensExcludedSubtree(name, attribs) {
|
|
51
75
|
if (SKIP_TAGS.has(name))
|
|
52
76
|
return true;
|
|
53
|
-
return
|
|
77
|
+
return hasSkippedRole(attribs['role']);
|
|
54
78
|
}
|
|
55
79
|
export const BLOCK_TAGS = new Set(['address', 'article', 'aside', 'blockquote', 'details', 'summary', 'dd', 'dl', 'dt', 'div', 'fieldset', 'figcaption', 'figure', 'footer', 'header', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hgroup', 'hr', 'li', 'main', 'ol', 'p', 'pre', 'section', 'table', 'ul', 'body', 'html', 'center', 'tr', 'td', 'th', 'thead', 'tbody', 'tfoot', 'caption']);
|
|
56
80
|
const HEADING_RE = /^h([1-6])$/;
|
|
@@ -158,8 +182,7 @@ function visibleCode(nodes, profile = 'generic') {
|
|
|
158
182
|
function isSkipped(el, root, profile = 'generic', ignoreHidden = false) {
|
|
159
183
|
if (SKIP_TAGS.has(el.name) && !(profile === 'starlight' && el.name === 'iframe' && iframeLink(el)))
|
|
160
184
|
return true;
|
|
161
|
-
|
|
162
|
-
if (SKIP_ROLES.has(role))
|
|
185
|
+
if (hasSkippedRole(el.attribs['role']))
|
|
163
186
|
return true;
|
|
164
187
|
if (el.attribs['hidden'] !== undefined && !ignoreHidden)
|
|
165
188
|
return true;
|
|
@@ -440,7 +463,7 @@ function taskState(li, profile = 'generic') {
|
|
|
440
463
|
if (node.name === 'input' && (node.attribs['type'] ?? '').toLowerCase() === 'checkbox') {
|
|
441
464
|
// The checkbox's own role counts as well: a checkbox with an excluded role (navigation, dialog and the rest of
|
|
442
465
|
// SKIP_ROLES) is left out like any other element with that role, so it cannot answer for the item (MP-10).
|
|
443
|
-
if (hiddenAttr(node) ||
|
|
466
|
+
if (hiddenAttr(node) || hasSkippedRole(node.attribs['role']))
|
|
444
467
|
continue;
|
|
445
468
|
return node.attribs['checked'] !== undefined;
|
|
446
469
|
}
|
|
@@ -739,13 +762,19 @@ function hiddenInPage(el) {
|
|
|
739
762
|
* (the maintainer's decision of 2026-10-02). A form with a left-out role still counts. */
|
|
740
763
|
function inExcludedSubtree(el) {
|
|
741
764
|
for (let cur = el; cur instanceof Element; cur = cur.parent) {
|
|
742
|
-
if (cur.name === 'form' && cur !== el && !
|
|
765
|
+
if (cur.name === 'form' && cur !== el && !hasSkippedRole(cur.attribs['role']))
|
|
743
766
|
continue;
|
|
744
767
|
if (isSkipped(cur, el))
|
|
745
768
|
return true;
|
|
746
769
|
}
|
|
747
770
|
return false;
|
|
748
771
|
}
|
|
772
|
+
/** The selector as an error names it. One that holds an at sign is read as an address: the reading a link target gets,
|
|
773
|
+
* or everything up to the last at sign as ***, so a selector that is a pasted URL with a password never reaches a
|
|
774
|
+
* report whole (0.2.43). */
|
|
775
|
+
function selectorValue(selector) {
|
|
776
|
+
return selector.includes('@') ? movedUserinfoMask(selector) ?? `***@${selector.slice(selector.lastIndexOf('@') + 1)}` : selector;
|
|
777
|
+
}
|
|
749
778
|
function pickRoot(doc, selector, notes, issues) {
|
|
750
779
|
if (selector) {
|
|
751
780
|
let matches;
|
|
@@ -756,11 +785,13 @@ function pickRoot(doc, selector, notes, issues) {
|
|
|
756
785
|
// The parser's message quotes the selector, so it is capped like the value (0.2.39, found by an outside review 2026-11-14).
|
|
757
786
|
// It quotes a piece of it in lower case or from the middle, where no masking can tell what the piece was, so a
|
|
758
787
|
// selector that holds a URL with a credential or a query value gets no quotation at all.
|
|
759
|
-
|
|
760
|
-
|
|
788
|
+
// An at sign alone is enough (0.2.43, PF5 of the second outside masking run): the parser's message quotes the
|
|
789
|
+
// text around it in lower case, and the value it names is masked by the reading a link target gets.
|
|
790
|
+
const quotes = selector.includes('@') || redactText(selector) !== stripControlChars(selector);
|
|
791
|
+
throw new HtmlExtractError(`Invalid selector: ${quotes ? 'the selector is not repeated, because it holds a URL with user information, a query value or a fragment' : capValue(err.message)}`, selectorValue(selector));
|
|
761
792
|
}
|
|
762
793
|
if (matches.length === 0)
|
|
763
|
-
throw new HtmlExtractError('Selector matched no element.', selector);
|
|
794
|
+
throw new HtmlExtractError('Selector matched no element.', selectorValue(selector));
|
|
764
795
|
if (matches.length > 1)
|
|
765
796
|
notes.push(`Selector "${capValue(selector)}" matched ${matches.length} elements; the first in document order was used.`);
|
|
766
797
|
return { root: matches[0], strategy: `selector:${capValue(selector)}`, confidence: 'high' };
|
package/dist/src/markdown.js
CHANGED
|
@@ -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, markBaseMaskedLinks, MAX_LINK_TARGET_CHARS, normalizeCode, resolveHref, shownField, shownNormalize, strictNormalize, userinfoSpansOf } from './normalize.js';
|
|
8
|
+
import { bareUserinfoSpansOf, movedUserinfoSpansOf, 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. */
|
|
@@ -232,7 +232,7 @@ function inline(ctx, node, run) {
|
|
|
232
232
|
if (at !== undefined && ctx.source[at] !== '[' && ctx.source[at] !== '<') {
|
|
233
233
|
if (insideHiddenUrlPart(ctx.source, at))
|
|
234
234
|
link.masked = true;
|
|
235
|
-
else if (ctx.source.includes('
|
|
235
|
+
else if (ctx.source.includes('//')) {
|
|
236
236
|
ctx.userinfo ??= userinfoSpansOf(ctx.source);
|
|
237
237
|
if (insideUserinfoSpan(ctx.userinfo, at))
|
|
238
238
|
link.masked = true;
|
|
@@ -242,6 +242,13 @@ function inline(ctx, node, run) {
|
|
|
242
242
|
if (insideUserinfoSpan(ctx.bareUserinfo, at))
|
|
243
243
|
link.masked = true;
|
|
244
244
|
}
|
|
245
|
+
// A link read out of a token that the report text masks as moved user information (0.2.43), as the
|
|
246
|
+
// e-mail address in ":secret@host.example/x".
|
|
247
|
+
if (!link.masked && ctx.source.includes('@')) {
|
|
248
|
+
ctx.movedUserinfo ??= movedUserinfoSpansOf(ctx.source);
|
|
249
|
+
if (insideUserinfoSpan(ctx.movedUserinfo, at))
|
|
250
|
+
link.masked = true;
|
|
251
|
+
}
|
|
245
252
|
}
|
|
246
253
|
run.links.push(link);
|
|
247
254
|
run.links.push(...inner.links);
|
package/dist/src/normalize.d.ts
CHANGED
|
@@ -67,8 +67,8 @@ export declare function insideHiddenUrlPart(text: string, at: number): boolean;
|
|
|
67
67
|
* authority, so "visit https://example.com for me@x.org" is prose. The authority does not go on past white
|
|
68
68
|
* space either when the text between its last colon and that white space is a port, one to five digits, or the end
|
|
69
69
|
* of a bracketed host, so "Use https://api.example.com:8443 or write to ops@example.org" keeps the address; a
|
|
70
|
-
* password of digits only that is followed by white space is therefore not masked.
|
|
71
|
-
*
|
|
70
|
+
* password of digits only that is followed by white space is therefore not masked. The report text uses it, and from
|
|
71
|
+
* 0.2.43 so do the numbers a number finding shows (hideUrlSecrets).
|
|
72
72
|
*/
|
|
73
73
|
export declare function maskAuthorityUserinfo(text: string, whiteSpaceInside?: boolean): string;
|
|
74
74
|
/** One user information found by findUserinfoSpans: start is the first character of the scheme, from the first
|
|
@@ -128,7 +128,7 @@ export declare function insideUserinfoSpan(spans: UserinfoSpan[], at: number): b
|
|
|
128
128
|
* A failed candidate is scanned to its own delimiter and a found one to its "@", so the scan stays linear. The result
|
|
129
129
|
* is a display aid and is never part of a comparison key.
|
|
130
130
|
*/
|
|
131
|
-
export declare function findBareUserinfoSpans(
|
|
131
|
+
export declare function findBareUserinfoSpans(source: string): UserinfoSpan[];
|
|
132
132
|
/** Masks the user information of every "label:name@host/path" that findBareUserinfoSpans finds, and leaves the label,
|
|
133
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
134
|
export declare function maskBareUserinfo(text: string): string;
|
|
@@ -141,6 +141,23 @@ export declare function bareUserinfoSpansOf(text: string): UserinfoSpan[];
|
|
|
141
141
|
* ANSI escape from a compared page or an argument cannot reach a plain --format text report (0.2.16, found by an
|
|
142
142
|
* outside review 2026-09-28). */
|
|
143
143
|
export declare function redactText(text: string): string;
|
|
144
|
+
/**
|
|
145
|
+
* Every token of a report text that movedUserinfoMask reads as hiding user information is shown as that function shows
|
|
146
|
+
* a link target (0.2.43, PF1 and K2-F5 of the second outside masking run): a token is the text between white space,
|
|
147
|
+
* angle brackets and double quotes, without the opening brackets and quotes and the closing brackets, quotes and
|
|
148
|
+
* punctuation around it. Before, only link targets had these rules, so the same address that a link finding showed
|
|
149
|
+
* as https://*** stood whole in an excerpt, a message or the text of a link. A password that holds white space cannot
|
|
150
|
+
* be read from one token: it is masked here only in the forms with "://" or a leading "//", which the user
|
|
151
|
+
* information rules of maskAuthorityUserinfo find. A token that overlaps a user information that those rules or
|
|
152
|
+
* maskBareUserinfo find in the whole text, such as postgres://user:secret@host/db, https://"admin":secret@host/ or
|
|
153
|
+
* user:secret@host.example/p, is left to them, so the documented shapes keep their output. Display only.
|
|
154
|
+
*/
|
|
155
|
+
export declare function maskMovedUserinfoTokens(text: string): string;
|
|
156
|
+
/** The tokens of a source text that maskMovedUserinfoTokens would replace, as spans whose `from` is the first character
|
|
157
|
+
* and `at` the last one, for the position test of insideUserinfoSpan: a link that a Markdown parser reads out of such
|
|
158
|
+
* a token, such as the e-mail address in ":secret@host.example/x", is shown masked. The characters that
|
|
159
|
+
* stripControlChars removes are read as a letter, which keeps every position. */
|
|
160
|
+
export declare function movedUserinfoSpansOf(text: string): UserinfoSpan[];
|
|
144
161
|
/**
|
|
145
162
|
* The text with the parts that maskHref hides taken out of every URL-like run: user information, query values
|
|
146
163
|
* and the fragment. Nothing else moves, and nothing is normalized, so every other number stays as it was.
|
package/dist/src/normalize.js
CHANGED
|
@@ -604,8 +604,8 @@ const isSpaceCode = (c) => (c < 0x80 ? c === 0x20 || (c >= 0x09 && c <= 0x0d) :
|
|
|
604
604
|
* authority, so "visit https://example.com for me@x.org" is prose. The authority does not go on past white
|
|
605
605
|
* space either when the text between its last colon and that white space is a port, one to five digits, or the end
|
|
606
606
|
* of a bracketed host, so "Use https://api.example.com:8443 or write to ops@example.org" keeps the address; a
|
|
607
|
-
* password of digits only that is followed by white space is therefore not masked.
|
|
608
|
-
*
|
|
607
|
+
* password of digits only that is followed by white space is therefore not masked. The report text uses it, and from
|
|
608
|
+
* 0.2.43 so do the numbers a number finding shows (hideUrlSecrets).
|
|
609
609
|
*/
|
|
610
610
|
export function maskAuthorityUserinfo(text, whiteSpaceInside = false) {
|
|
611
611
|
const spans = findUserinfoSpans(text, whiteSpaceInside);
|
|
@@ -634,18 +634,34 @@ export function findUserinfoSpans(text, whiteSpaceInside = false) {
|
|
|
634
634
|
const spans = [];
|
|
635
635
|
let pos = 0;
|
|
636
636
|
let from = 0;
|
|
637
|
+
// The next "://", searched again only when the text up to it is behind: -2 is not searched yet, -1 is none left.
|
|
638
|
+
let colonAt = -2;
|
|
637
639
|
for (;;) {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
640
|
+
if (colonAt === -2 || (colonAt >= 0 && colonAt < from))
|
|
641
|
+
colonAt = text.indexOf('://', from);
|
|
642
|
+
// With whiteSpaceInside, the authority of a network-path reference, "//name:secret@host/p" with no scheme, counts
|
|
643
|
+
// too (0.2.43): a report shows the same text a link target would, and movedUserinfoMask reads that target.
|
|
644
|
+
const bare = whiteSpaceInside ? indexOfBareSlashes(text, from, colonAt < 0 ? text.length : colonAt) : -1;
|
|
645
|
+
let start;
|
|
646
|
+
let authFrom;
|
|
642
647
|
let hasLetter = false;
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
+
if (bare >= 0) {
|
|
649
|
+
start = bare;
|
|
650
|
+
authFrom = bare + 2;
|
|
651
|
+
hasLetter = true;
|
|
652
|
+
}
|
|
653
|
+
else {
|
|
654
|
+
if (colonAt < 0)
|
|
655
|
+
break;
|
|
656
|
+
authFrom = colonAt + 3;
|
|
657
|
+
start = colonAt;
|
|
658
|
+
for (let k = colonAt; k > pos && isSchemeChar(text.charCodeAt(k - 1)); k--) {
|
|
659
|
+
start = k - 1;
|
|
660
|
+
if (isLetter(text.charCodeAt(k - 1)))
|
|
661
|
+
hasLetter = true;
|
|
662
|
+
}
|
|
648
663
|
}
|
|
664
|
+
from = authFrom;
|
|
649
665
|
if (!hasLetter)
|
|
650
666
|
continue;
|
|
651
667
|
let at = -1;
|
|
@@ -673,7 +689,10 @@ export function findUserinfoSpans(text, whiteSpaceInside = false) {
|
|
|
673
689
|
}
|
|
674
690
|
if (c === 0x3a) {
|
|
675
691
|
lastColon = e;
|
|
676
|
-
|
|
692
|
+
// A tab after the colon is removed by the URL parser, so it does not make the colon a label of prose as a plain
|
|
693
|
+
// space does (0.2.43, QA-2 D5). A line break stays prose here: "host:" at the end of a line is a label.
|
|
694
|
+
const next = text.charCodeAt(e + 1);
|
|
695
|
+
if (firstColon < 0 && (!isSpaceCode(next) || next === 0x09))
|
|
677
696
|
firstColon = e;
|
|
678
697
|
}
|
|
679
698
|
if (c === 0x40) {
|
|
@@ -686,12 +705,32 @@ export function findUserinfoSpans(text, whiteSpaceInside = false) {
|
|
|
686
705
|
at = lastAt;
|
|
687
706
|
if (at < 0)
|
|
688
707
|
continue;
|
|
689
|
-
|
|
708
|
+
// A network-path reference without a scheme counts only with a colon in front of its "@", a password, as in
|
|
709
|
+
// //name:secret@host/p; "//name@host/p" holds no secret the report text needs to hide.
|
|
710
|
+
if (bare >= 0 && !(firstColon >= 0 && firstColon < at))
|
|
711
|
+
continue;
|
|
712
|
+
spans.push({ start, from: authFrom, at });
|
|
690
713
|
pos = at + 1;
|
|
691
714
|
from = pos;
|
|
692
715
|
}
|
|
693
716
|
return spans;
|
|
694
717
|
}
|
|
718
|
+
/** The first "//" in text[from, limit) that starts a network-path reference: the start of the text, or a character
|
|
719
|
+
* that is not a scheme character, a colon, a slash or a backslash in front of it. "a.example//b", "x://y" and "/a//b"
|
|
720
|
+
* hold none. */
|
|
721
|
+
function indexOfBareSlashes(text, from, limit) {
|
|
722
|
+
let i = from;
|
|
723
|
+
while (i < limit) {
|
|
724
|
+
i = text.indexOf('//', i);
|
|
725
|
+
if (i < 0 || i >= limit)
|
|
726
|
+
return -1;
|
|
727
|
+
const prev = i === 0 ? -1 : text.charCodeAt(i - 1);
|
|
728
|
+
if (prev === -1 || !(isSchemeChar(prev) || prev === 0x3a || prev === 0x2f || prev === 0x5c))
|
|
729
|
+
return i;
|
|
730
|
+
i++;
|
|
731
|
+
}
|
|
732
|
+
return -1;
|
|
733
|
+
}
|
|
695
734
|
/** The text as a report shows it, for a raw text whose white space the credential masking needs: undefined when
|
|
696
735
|
* dropAuthorityControls changes nothing, else the normalized text without the white space inside user information.
|
|
697
736
|
* It is for display only. The comparison keys come from strictNormalize alone, as in 0.2.38, because removing the
|
|
@@ -719,20 +758,29 @@ const CONTROL_WHITE_SPACE = /[\t\n\v\f\r]/;
|
|
|
719
758
|
* address is ordinary text.
|
|
720
759
|
*/
|
|
721
760
|
export function dropAuthorityControls(text) {
|
|
722
|
-
if (!CONTROL_WHITE_SPACE.test(text) || !text.includes('
|
|
761
|
+
if (!CONTROL_WHITE_SPACE.test(text) || !text.includes('//'))
|
|
723
762
|
return text;
|
|
724
763
|
let out = '';
|
|
725
764
|
let pos = 0;
|
|
726
765
|
let from = 0;
|
|
727
766
|
for (;;) {
|
|
728
767
|
const colon = text.indexOf('://', from);
|
|
729
|
-
|
|
768
|
+
// A network-path reference, "//name:secret@host/p", is read too (0.2.43, QA-2 D5): the tab after its colon is part of
|
|
769
|
+
// the user information, and the page text has turned it into a space by the time the masking reads it.
|
|
770
|
+
const bare = indexOfBareSlashes(text, from, colon < 0 ? text.length : colon);
|
|
771
|
+
if (colon < 0 && bare < 0)
|
|
730
772
|
break;
|
|
731
|
-
from = colon + 3;
|
|
732
773
|
let hasLetter = false;
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
774
|
+
if (bare >= 0) {
|
|
775
|
+
from = bare + 2;
|
|
776
|
+
hasLetter = true;
|
|
777
|
+
}
|
|
778
|
+
else {
|
|
779
|
+
from = colon + 3;
|
|
780
|
+
for (let k = colon; k > pos && isSchemeChar(text.charCodeAt(k - 1)); k--) {
|
|
781
|
+
if (isLetter(text.charCodeAt(k - 1)))
|
|
782
|
+
hasLetter = true;
|
|
783
|
+
}
|
|
736
784
|
}
|
|
737
785
|
if (!hasLetter)
|
|
738
786
|
continue;
|
|
@@ -770,6 +818,9 @@ export function dropAuthorityControls(text) {
|
|
|
770
818
|
}
|
|
771
819
|
if (firstControl < 0)
|
|
772
820
|
continue;
|
|
821
|
+
// Without a scheme the reference counts only with a colon in front of the "@": "//name@host" holds no secret.
|
|
822
|
+
if (bare >= 0 && !colonRule)
|
|
823
|
+
continue;
|
|
773
824
|
if (lastColon >= 0 && isPortText(text, lastColon + 1, firstControl))
|
|
774
825
|
continue;
|
|
775
826
|
if (firstControl > from && text.charCodeAt(firstControl - 1) === 0x5d)
|
|
@@ -862,8 +913,11 @@ function isBareHostText(t, from, to) {
|
|
|
862
913
|
* A failed candidate is scanned to its own delimiter and a found one to its "@", so the scan stays linear. The result
|
|
863
914
|
* is a display aid and is never part of a comparison key.
|
|
864
915
|
*/
|
|
865
|
-
export function findBareUserinfoSpans(
|
|
916
|
+
export function findBareUserinfoSpans(source) {
|
|
866
917
|
const spans = [];
|
|
918
|
+
// A tab right after the colon belongs to the user information, as it does after "://" (the other white space ends
|
|
919
|
+
// the run). The tab is read as a letter, which keeps every position, so the spans index the source text.
|
|
920
|
+
const text = source.includes(':\t') ? source.replace(/:\t/g, ':a') : source;
|
|
867
921
|
const runs = new RegExp(RUN.source, RUN.flags);
|
|
868
922
|
for (let run = runs.exec(text); run !== null; run = runs.exec(text)) {
|
|
869
923
|
const s = run.index;
|
|
@@ -952,7 +1006,101 @@ export function redactText(text) {
|
|
|
952
1006
|
// The control characters go first as well as last: a vertical tab, a form feed, U+2028 or U+0085 inside the user
|
|
953
1007
|
// information would otherwise end the authority for the masking and be removed afterwards, which left a credential
|
|
954
1008
|
// that read as a whole URL.
|
|
955
|
-
|
|
1009
|
+
// maskMovedUserinfoTokens runs before the run-based masking, which rewrites an address and so would reformat
|
|
1010
|
+
// https://CORP\erik:secret@host/x into https://corp/erik:secret@host/x before any rule could read what was written.
|
|
1011
|
+
return stripControlChars(rewriteUrlRuns(maskBareUserinfo(maskAuthorityUserinfo(maskMovedUserinfoTokens(maskParenUserinfo(stripControlChars(text))), true)), maskHref));
|
|
1012
|
+
}
|
|
1013
|
+
/**
|
|
1014
|
+
* Every token of a report text that movedUserinfoMask reads as hiding user information is shown as that function shows
|
|
1015
|
+
* a link target (0.2.43, PF1 and K2-F5 of the second outside masking run): a token is the text between white space,
|
|
1016
|
+
* angle brackets and double quotes, without the opening brackets and quotes and the closing brackets, quotes and
|
|
1017
|
+
* punctuation around it. Before, only link targets had these rules, so the same address that a link finding showed
|
|
1018
|
+
* as https://*** stood whole in an excerpt, a message or the text of a link. A password that holds white space cannot
|
|
1019
|
+
* be read from one token: it is masked here only in the forms with "://" or a leading "//", which the user
|
|
1020
|
+
* information rules of maskAuthorityUserinfo find. A token that overlaps a user information that those rules or
|
|
1021
|
+
* maskBareUserinfo find in the whole text, such as postgres://user:secret@host/db, https://"admin":secret@host/ or
|
|
1022
|
+
* user:secret@host.example/p, is left to them, so the documented shapes keep their output. Display only.
|
|
1023
|
+
*/
|
|
1024
|
+
export function maskMovedUserinfoTokens(text) {
|
|
1025
|
+
if (!text.includes('@'))
|
|
1026
|
+
return text;
|
|
1027
|
+
let own = null;
|
|
1028
|
+
let bare = null;
|
|
1029
|
+
// A tab right after a colon does not end the token, as it does not end the user information (findBareUserinfoSpans).
|
|
1030
|
+
return text.replace(/(?:[^\s<>"]|(?<=:)\t)+/gu, (token, offset) => {
|
|
1031
|
+
if (!token.includes('@'))
|
|
1032
|
+
return token;
|
|
1033
|
+
const [lead, end] = tokenCore(token);
|
|
1034
|
+
const core = token.slice(lead, end);
|
|
1035
|
+
const shown = movedUserinfoMask(core);
|
|
1036
|
+
if (shown === null || !credentialShaped(core))
|
|
1037
|
+
return token;
|
|
1038
|
+
own ??= findUserinfoSpans(text, true);
|
|
1039
|
+
bare ??= findBareUserinfoSpans(text);
|
|
1040
|
+
// Left to those rules only when one of them ends at the last "@" of the token, so that it masks as far as this one
|
|
1041
|
+
// would; https://erik@corp:secret#x@host/ has a span that ends at its first "@" and is masked here.
|
|
1042
|
+
const lastAt = offset + token.lastIndexOf('@');
|
|
1043
|
+
if (spanEndsAt(own, lastAt) || spanEndsAt(bare, lastAt))
|
|
1044
|
+
return token;
|
|
1045
|
+
// The word in front of the colon keeps the case it was written in: only the link-target reading lower-cases it.
|
|
1046
|
+
const word = /^[a-z][a-z0-9+.-]*/i.exec(core);
|
|
1047
|
+
const shownCased = word !== null && shown.startsWith(word[0].toLowerCase() + ':') ? word[0] + shown.slice(word[0].length) : shown;
|
|
1048
|
+
return token.slice(0, lead) + shownCased + token.slice(end);
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
/** Whether the text before the last "@" of a token, after a scheme word, holds a colon or a backslash, a question mark
|
|
1052
|
+
* or a number sign: running text shows "https:example.com/@user/post" and "see:the@docs" as they are, where a link
|
|
1053
|
+
* target of the same shape is masked, because a target is never prose. */
|
|
1054
|
+
function credentialShaped(core) {
|
|
1055
|
+
const word = /^[a-z][a-z0-9+.-]*:/i.exec(core);
|
|
1056
|
+
const from = word === null ? 0 : word[0].length;
|
|
1057
|
+
const between = core.slice(from, core.lastIndexOf('@'));
|
|
1058
|
+
return between.includes(':') || (core.length > 1 && /[#?\\]/.test(between));
|
|
1059
|
+
}
|
|
1060
|
+
/** Whether one of the sorted, disjoint spans ends at the "@" at position at. */
|
|
1061
|
+
function spanEndsAt(spans, at) {
|
|
1062
|
+
let lo = 0;
|
|
1063
|
+
let hi = spans.length - 1;
|
|
1064
|
+
while (lo < hi) {
|
|
1065
|
+
const mid = (lo + hi) >> 1;
|
|
1066
|
+
if (spans[mid].at < at)
|
|
1067
|
+
lo = mid + 1;
|
|
1068
|
+
else
|
|
1069
|
+
hi = mid;
|
|
1070
|
+
}
|
|
1071
|
+
return spans[lo]?.at === at;
|
|
1072
|
+
}
|
|
1073
|
+
/** The part of a token that maskMovedUserinfoTokens reads: [first, end) without the opening brackets and quotes and
|
|
1074
|
+
* the closing brackets, quotes and punctuation. */
|
|
1075
|
+
function tokenCore(token) {
|
|
1076
|
+
let lead = 0;
|
|
1077
|
+
while (lead < token.length && "'([{".includes(token[lead]))
|
|
1078
|
+
lead++;
|
|
1079
|
+
let end = token.length;
|
|
1080
|
+
while (end > lead && ")']}.,;!".includes(token[end - 1]))
|
|
1081
|
+
end--;
|
|
1082
|
+
return [lead, end];
|
|
1083
|
+
}
|
|
1084
|
+
/** The tokens of a source text that maskMovedUserinfoTokens would replace, as spans whose `from` is the first character
|
|
1085
|
+
* and `at` the last one, for the position test of insideUserinfoSpan: a link that a Markdown parser reads out of such
|
|
1086
|
+
* a token, such as the e-mail address in ":secret@host.example/x", is shown masked. The characters that
|
|
1087
|
+
* stripControlChars removes are read as a letter, which keeps every position. */
|
|
1088
|
+
export function movedUserinfoSpansOf(text) {
|
|
1089
|
+
const spans = [];
|
|
1090
|
+
if (!text.includes('@'))
|
|
1091
|
+
return spans;
|
|
1092
|
+
const plain = text.replace(CONTROL_CHARS, (m) => 'a'.repeat(m.length));
|
|
1093
|
+
const tokens = /[^\s<>"]+/gu;
|
|
1094
|
+
for (let t = tokens.exec(plain); t !== null; t = tokens.exec(plain)) {
|
|
1095
|
+
const token = t[0];
|
|
1096
|
+
if (!token.includes('@'))
|
|
1097
|
+
continue;
|
|
1098
|
+
const [lead, end] = tokenCore(token);
|
|
1099
|
+
if (movedUserinfoMask(token.slice(lead, end)) === null)
|
|
1100
|
+
continue;
|
|
1101
|
+
spans.push({ start: t.index + lead, from: t.index + lead, at: t.index + end - 1 });
|
|
1102
|
+
}
|
|
1103
|
+
return spans;
|
|
956
1104
|
}
|
|
957
1105
|
/**
|
|
958
1106
|
* The text with the parts that maskHref hides taken out of every URL-like run: user information, query values
|
|
@@ -964,7 +1112,10 @@ export function hideUrlSecrets(text) {
|
|
|
964
1112
|
// review 2026-09-28): up to here only redactText applied it, so visibleNumbers below still read a
|
|
965
1113
|
// number straight out of an unmasked "(name):secret@" that the general run-based scan cannot see as
|
|
966
1114
|
// one run (see the comment on PAREN_USERINFO_START above).
|
|
967
|
-
|
|
1115
|
+
// The forms that redactText masks with the reading of a link target, and the scheme-less name:secret@host, are taken
|
|
1116
|
+
// out too (0.2.43, QA-2 D1): a password of digits only inside them would otherwise be read as a number and reach
|
|
1117
|
+
// NUMBER_CHANGED. White space inside the user information stays out of this reading, as above.
|
|
1118
|
+
return rewriteUrlRuns(maskBareUserinfo(maskAuthorityUserinfo(maskMovedUserinfoTokens(maskParenUserinfo(text)), true)), withoutUrlSecrets);
|
|
968
1119
|
}
|
|
969
1120
|
/**
|
|
970
1121
|
* The numeric tokens a report may show. extractNumbers reads the whole text, so a numeric query value, such as
|
|
@@ -1141,7 +1292,16 @@ export function movedUserinfoMask(written) {
|
|
|
1141
1292
|
}
|
|
1142
1293
|
if (special)
|
|
1143
1294
|
return shown;
|
|
1144
|
-
|
|
1295
|
+
const before = rest.slice(0, rest.lastIndexOf('@'));
|
|
1296
|
+
if (before.includes(':'))
|
|
1297
|
+
return `${name}:***`;
|
|
1298
|
+
// user:secret#x@host.example/p, user:ab?secret@host/p, user:secret x@host/p and user:secret\x@host/p: the secret
|
|
1299
|
+
// stands in front of a delimiter that ends the span maskBareUserinfo reads, so only the scheme word is shown, as
|
|
1300
|
+
// for a colon in the user information (0.2.43, PL1 and PF3 of the second outside masking run). A one-letter
|
|
1301
|
+
// word is a drive letter, as in C:\dir\file@2x.png, and stays.
|
|
1302
|
+
if (name.length > 1 && /[\s#?\\]/.test(before))
|
|
1303
|
+
return `${name}:***`;
|
|
1304
|
+
return null;
|
|
1145
1305
|
}
|
|
1146
1306
|
if (name === 'file')
|
|
1147
1307
|
return shown;
|
package/dist/src/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const TOOL_NAME = "markdown-parity-check";
|
|
2
|
-
export declare const TOOL_VERSION = "0.2.
|
|
2
|
+
export declare const TOOL_VERSION = "0.2.43";
|
package/dist/src/version.js
CHANGED
|
@@ -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.
|
|
5
|
+
export const TOOL_VERSION = '0.2.43';
|
package/package.json
CHANGED