agent-sanitizer 2.63.1 → 2.64.1
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/LICENSE-THIRD-PARTY +27 -0
- package/THREAT-MODEL.md +7 -3
- package/package.json +1 -1
- package/src/cf-charset.mjs +5 -4
- package/src/css-syntax-data.mjs +274 -0
- package/src/html-tree-adapter.mjs +113 -1
- package/src/html.mjs +873 -354
- package/src/joining-type.mjs +4 -3
- package/src/standardized-variants.mjs +4 -4
- package/src/unicode-properties.mjs +4 -3
- package/src/url-attributes.mjs +76 -0
- package/types/cf-charset.d.mts +5 -4
- package/types/css-syntax-data.d.mts +6 -0
- package/types/html-tree-adapter.d.mts +43 -0
- package/types/html.d.mts +43 -7
- package/types/joining-type.d.mts +4 -3
- package/types/src/cf-charset.d.mts +5 -4
- package/types/src/joining-type.d.mts +4 -3
- package/types/src/standardized-variants.d.mts +3 -3
- package/types/src/unicode-properties.d.mts +4 -3
- package/types/standardized-variants.d.mts +3 -3
- package/types/unicode-properties.d.mts +4 -3
- package/types/url-attributes.d.mts +11 -0
package/LICENSE-THIRD-PARTY
CHANGED
|
@@ -26,3 +26,30 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
26
26
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
27
27
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
28
28
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
29
|
+
|
|
30
|
+
src/css-syntax-data.mjs
|
|
31
|
+
CSS value grammars extracted by scripts/gen-css-syntax.mjs from
|
|
32
|
+
css-tree@3.2.1's definition-syntax-data (mdn-data@2.27.1, CC0 1.0, plus
|
|
33
|
+
css-tree's own patch). css-tree's licence follows.
|
|
34
|
+
|
|
35
|
+
(The MIT License)
|
|
36
|
+
|
|
37
|
+
Copyright (C) 2016-2026 by Roman Dvornov
|
|
38
|
+
|
|
39
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
40
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
41
|
+
in the Software without restriction, including without limitation the rights
|
|
42
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
43
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
44
|
+
furnished to do so, subject to the following conditions:
|
|
45
|
+
|
|
46
|
+
The above copyright notice and this permission notice shall be included in
|
|
47
|
+
all copies or substantial portions of the Software.
|
|
48
|
+
|
|
49
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
50
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
51
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
52
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
53
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
54
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
55
|
+
THE SOFTWARE.
|
package/THREAT-MODEL.md
CHANGED
|
@@ -142,9 +142,13 @@ exfil-shaped URLs.
|
|
|
142
142
|
|
|
143
143
|
## Layer 3—exfil URLs (detection only)
|
|
144
144
|
|
|
145
|
-
Report—never rewrite—URLs in markdown links/images/definitions
|
|
146
|
-
attributes (`src
|
|
147
|
-
`
|
|
145
|
+
Report—never rewrite—URLs in markdown links/images/definitions, every HTML/SVG
|
|
146
|
+
URL attribute in `src/url-attributes.mjs` (`src`, `href`, `xlink:href`,
|
|
147
|
+
`srcset`/`imagesrcset`, `ping`, `poster`, `object data`, form
|
|
148
|
+
`action`/`formaction`, `meta refresh`, …), CSS `url()` in `style` attributes and
|
|
149
|
+
`<style>` elements, and the same again inside HTML comments, that are shaped to
|
|
150
|
+
carry data off-origin. A URL's scheme is read by the WHATWG URL parser, and
|
|
151
|
+
`srcset` and `meta refresh` by ports of the HTML Standard's own parsing steps:
|
|
148
152
|
|
|
149
153
|
- suspicious query/fragment parameters (long base64/hex blobs, credential-shaped
|
|
150
154
|
tokens), tuned to skip request-signing / pagination / analytics parameters
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-sanitizer",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.64.1",
|
|
4
4
|
"description": "Defend an agent against hidden-content injection: strip payload-capable invisible Unicode and ANSI, splice out human-invisible HTML, and flag data-exfil URLs in untrusted text before any model sees it.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
package/src/cf-charset.mjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* GENERATED by scripts/gen-
|
|
3
|
-
* (General_Category=Cf, Unicode 17.0.0)
|
|
2
|
+
* GENERATED by scripts/gen-cf-charset.mjs from the pinned UCD
|
|
3
|
+
* (General_Category=Cf, Unicode 17.0.0) at install, pack and build
|
|
4
|
+
* time; git-ignored, never committed — DO NOT EDIT.
|
|
4
5
|
*
|
|
5
6
|
* The general-category Cf code points, PINNED at generation time. invisible.mjs
|
|
6
7
|
* strips exactly this set instead of asking the runtime for Cf, and the Python port
|
|
7
8
|
* reads the SAME set from data/invisible-charset.json's `cf_codepoints`, so both
|
|
8
9
|
* layers strip an identical Cf set regardless of each runtime's own Unicode
|
|
9
|
-
* version. Regenerate with `node scripts/gen-
|
|
10
|
-
*
|
|
10
|
+
* version. Regenerate with `node scripts/gen-cf-charset.mjs` (`pnpm install`
|
|
11
|
+
* does).
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
14
|
export const UNICODE_VERSION = "17.0.0";
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/** GENERATED by scripts/gen-css-syntax.mjs — DO NOT EDIT (mdn-data, CC0). */
|
|
2
|
+
// Stryker disable all — generated; its correctness is the round-trip test.
|
|
3
|
+
/** @type {{ types: Record<string, string>, properties: Record<string, string> }} */
|
|
4
|
+
export const CSS_SYNTAX = {
|
|
5
|
+
types: {
|
|
6
|
+
"-legacy-gradient": "<-webkit-gradient()> | <-legacy-linear-gradient> | <-legacy-repeating-linear-gradient> | <-legacy-radial-gradient> | <-legacy-repeating-radial-gradient>",
|
|
7
|
+
"-legacy-linear-gradient": "-moz-linear-gradient( <-legacy-linear-gradient-arguments> ) | -webkit-linear-gradient( <-legacy-linear-gradient-arguments> ) | -o-linear-gradient( <-legacy-linear-gradient-arguments> )",
|
|
8
|
+
"-legacy-linear-gradient-arguments": "[ <angle> | <side-or-corner> ]? , <color-stop-list>",
|
|
9
|
+
"-legacy-radial-gradient": "-moz-radial-gradient( <-legacy-radial-gradient-arguments> ) | -webkit-radial-gradient( <-legacy-radial-gradient-arguments> ) | -o-radial-gradient( <-legacy-radial-gradient-arguments> )",
|
|
10
|
+
"-legacy-radial-gradient-arguments": "[ <position> , ]? [ [ [ <-legacy-radial-gradient-shape> || <-legacy-radial-gradient-size> ] | [ <length> | <percentage> ]{2} ] , ]? <color-stop-list>",
|
|
11
|
+
"-legacy-radial-gradient-shape": "circle | ellipse",
|
|
12
|
+
"-legacy-radial-gradient-size": "closest-side | closest-corner | farthest-side | farthest-corner | contain | cover",
|
|
13
|
+
"-legacy-repeating-linear-gradient": "-moz-repeating-linear-gradient( <-legacy-linear-gradient-arguments> ) | -webkit-repeating-linear-gradient( <-legacy-linear-gradient-arguments> ) | -o-repeating-linear-gradient( <-legacy-linear-gradient-arguments> )",
|
|
14
|
+
"-legacy-repeating-radial-gradient": "-moz-repeating-radial-gradient( <-legacy-radial-gradient-arguments> ) | -webkit-repeating-radial-gradient( <-legacy-radial-gradient-arguments> ) | -o-repeating-radial-gradient( <-legacy-radial-gradient-arguments> )",
|
|
15
|
+
"-ms-filter-function": "<-ms-filter-function-progid> | <-ms-filter-function-legacy>",
|
|
16
|
+
"-ms-filter-function-legacy": "<ident-token> | <function-token> <any-value>? )",
|
|
17
|
+
"-ms-filter-function-list": "<-ms-filter-function>+",
|
|
18
|
+
"-ms-filter-function-progid": "'progid:' [ <ident-token> '.' ]* [ <ident-token> | <function-token> <any-value>? ) ]",
|
|
19
|
+
"-non-standard-color": "-moz-ButtonDefault | -moz-ButtonHoverFace | -moz-ButtonHoverText | -moz-CellHighlight | -moz-CellHighlightText | -moz-Combobox | -moz-ComboboxText | -moz-Dialog | -moz-DialogText | -moz-dragtargetzone | -moz-EvenTreeRow | -moz-Field | -moz-FieldText | -moz-html-CellHighlight | -moz-html-CellHighlightText | -moz-mac-accentdarkestshadow | -moz-mac-accentdarkshadow | -moz-mac-accentface | -moz-mac-accentlightesthighlight | -moz-mac-accentlightshadow | -moz-mac-accentregularhighlight | -moz-mac-accentregularshadow | -moz-mac-chrome-active | -moz-mac-chrome-inactive | -moz-mac-focusring | -moz-mac-menuselect | -moz-mac-menushadow | -moz-mac-menutextselect | -moz-MenuHover | -moz-MenuHoverText | -moz-MenuBarText | -moz-MenuBarHoverText | -moz-nativehyperlinktext | -moz-OddTreeRow | -moz-win-communicationstext | -moz-win-mediatext | -moz-activehyperlinktext | -moz-default-background-color | -moz-default-color | -moz-hyperlinktext | -moz-visitedhyperlinktext | -webkit-activelink | -webkit-focus-ring-color | -webkit-link | -webkit-text",
|
|
20
|
+
"-non-standard-display": "-ms-inline-flexbox | -ms-grid | -ms-inline-grid | -webkit-flex | -webkit-inline-flex | -webkit-box | -webkit-inline-box | -moz-inline-stack | -moz-box | -moz-inline-box",
|
|
21
|
+
"-non-standard-font": "-apple-system-body | -apple-system-headline | -apple-system-subheadline | -apple-system-caption1 | -apple-system-caption2 | -apple-system-footnote | -apple-system-short-body | -apple-system-short-headline | -apple-system-short-subheadline | -apple-system-short-caption1 | -apple-system-short-footnote | -apple-system-tall-body",
|
|
22
|
+
"-non-standard-generic-family": "-apple-system | BlinkMacSystemFont",
|
|
23
|
+
"-non-standard-overflow": "overlay | -moz-scrollbars-none | -moz-scrollbars-horizontal | -moz-scrollbars-vertical | -moz-hidden-unscrollable",
|
|
24
|
+
"-non-standard-size": "intrinsic | min-intrinsic | -webkit-fill-available | -webkit-fit-content | -webkit-min-content | -webkit-max-content | -moz-available | -moz-fit-content | -moz-min-content | -moz-max-content",
|
|
25
|
+
"-webkit-gradient()": "-webkit-gradient( <-webkit-gradient-type>, <-webkit-gradient-point> [, <-webkit-gradient-point> | , <-webkit-gradient-radius>, <-webkit-gradient-point> ] [, <-webkit-gradient-radius>]? [, <-webkit-gradient-color-stop>]* )",
|
|
26
|
+
"-webkit-gradient-color-stop": "from( <color> ) | color-stop( [ <number-zero-one> | <percentage> ] , <color> ) | to( <color> )",
|
|
27
|
+
"-webkit-gradient-point": "[ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ]",
|
|
28
|
+
"-webkit-gradient-radius": "<length> | <percentage>",
|
|
29
|
+
"-webkit-gradient-type": "linear | radial",
|
|
30
|
+
"absolute-size": "xx-small | x-small | small | medium | large | x-large | xx-large | xxx-large",
|
|
31
|
+
"alpha-value": "<number> | <percentage>",
|
|
32
|
+
"anchor()": "anchor( <anchor-name>? && <anchor-side>, <length-percentage>? )",
|
|
33
|
+
"anchor-name": "<dashed-ident>",
|
|
34
|
+
"anchor-side": "inside | outside | top | left | right | bottom | start | end | self-start | self-end | <percentage> | center",
|
|
35
|
+
"anchor-size()": "anchor-size( [ <anchor-name> || <anchor-size> ]? , <length-percentage>? )",
|
|
36
|
+
"anchor-size": "width | height | block | inline | self-block | self-inline",
|
|
37
|
+
"angle-percentage": "<angle> | <percentage>",
|
|
38
|
+
"angular-color-hint": "<angle-percentage> | <zero>",
|
|
39
|
+
"angular-color-stop": "<color> <color-stop-angle>?",
|
|
40
|
+
"angular-color-stop-list": "<angular-color-stop> , [ <angular-color-hint>? , <angular-color-stop> ]#?",
|
|
41
|
+
"attachment": "scroll | fixed | local",
|
|
42
|
+
"basic-shape": "<inset()> | <xywh()> | <rect()> | <circle()> | <ellipse()> | <polygon()> | <path()>",
|
|
43
|
+
"bg-clip": "<visual-box> | border-area | text",
|
|
44
|
+
"bg-image": "<image> | none",
|
|
45
|
+
"bg-layer": "<bg-image> || <bg-position> [ / <bg-size> ]? || <repeat-style> || <attachment> || <visual-box> || <visual-box>",
|
|
46
|
+
"bg-position": "[ [ left | center | right | top | bottom | <length-percentage> ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ] | [ center | [ left | right ] <length-percentage>? ] && [ center | [ top | bottom ] <length-percentage>? ] ]",
|
|
47
|
+
"bg-size": "[ <length-percentage [0,∞]> | auto ]{1,2} | cover | contain",
|
|
48
|
+
"blur()": "blur( <length>? )",
|
|
49
|
+
"bottom": "<length> | auto",
|
|
50
|
+
"brightness()": "brightness( [ <number> | <percentage> ]? )",
|
|
51
|
+
"calc-constant": "e | pi | infinity | -infinity | NaN",
|
|
52
|
+
"calc-product": "<calc-value> [ '*' <calc-value> | '/' <number> ]*",
|
|
53
|
+
"calc-size()": "calc-size( <calc-size-basis>, <calc-sum> )",
|
|
54
|
+
"calc-size-basis": "<intrinsic-size-keyword> | <calc-size()> | any | <calc-sum>",
|
|
55
|
+
"calc-sum": "<calc-product> [ [ '+' | '-' ] <calc-product> ]*",
|
|
56
|
+
"calc-value": "<number> | <dimension> | <percentage> | <calc-constant> | ( <calc-sum> )",
|
|
57
|
+
"cf-final-image": "<image> | <color>",
|
|
58
|
+
"cf-mixing-image": "<percentage>? && <image>",
|
|
59
|
+
"circle()": "circle( <radial-size>? [ at <position> ]? )",
|
|
60
|
+
"clip-source": "<url>",
|
|
61
|
+
"cmyk-component": "<number> | <percentage> | none",
|
|
62
|
+
"color()": "color( <colorspace-params> [ / [ <alpha-value> | none ] ]? )",
|
|
63
|
+
"color": "<color-base> | currentColor | <system-color> | <device-cmyk()> | <light-dark()> | <-non-standard-color>",
|
|
64
|
+
"color-base": "<hex-color> | <color-function> | <named-color> | <color-mix()> | transparent",
|
|
65
|
+
"color-function": "<rgb()> | <rgba()> | <hsl()> | <hsla()> | <hwb()> | <lab()> | <lch()> | <oklab()> | <oklch()> | <color()>",
|
|
66
|
+
"color-interpolation-method": "in [ <rectangular-color-space> | <polar-color-space> <hue-interpolation-method>? | <custom-color-space> ]",
|
|
67
|
+
"color-mix()": "color-mix( <color-interpolation-method> , [ <color> && <percentage [0,100]>? ]#{2} )",
|
|
68
|
+
"color-stop-angle": "[ <angle-percentage> | <zero> ]{1,2}",
|
|
69
|
+
"color-stop-length": "<length-percentage>{1,2}",
|
|
70
|
+
"color-stop-list": "<linear-color-stop> , [ <linear-color-hint>? , <linear-color-stop> ]#?",
|
|
71
|
+
"colorspace-params": "[ <predefined-rgb-params> | <xyz-params>]",
|
|
72
|
+
"conic-gradient()": "conic-gradient( [ <conic-gradient-syntax> ] )",
|
|
73
|
+
"conic-gradient-syntax": "[ [ [ from [ <angle> | <zero> ] ]? [ at <position> ]? ] || <color-interpolation-method> ]? , <angular-color-stop-list>",
|
|
74
|
+
"contrast()": "contrast( [ <number> | <percentage> ]? )",
|
|
75
|
+
"cross-fade()": "cross-fade( <cf-mixing-image> , <cf-final-image>? )",
|
|
76
|
+
"custom-color-space": "<dashed-ident>",
|
|
77
|
+
"device-cmyk()": "<legacy-device-cmyk-syntax> | <modern-device-cmyk-syntax>",
|
|
78
|
+
"display-box": "contents | none",
|
|
79
|
+
"display-inside": "flow | flow-root | table | flex | grid | ruby",
|
|
80
|
+
"display-internal": "table-row-group | table-header-group | table-footer-group | table-row | table-cell | table-column-group | table-column | table-caption | ruby-base | ruby-text | ruby-base-container | ruby-text-container",
|
|
81
|
+
"display-legacy": "inline-block | inline-list-item | inline-table | inline-flex | inline-grid",
|
|
82
|
+
"display-listitem": "<display-outside>? && [ flow | flow-root ]? && list-item",
|
|
83
|
+
"display-outside": "block | inline | run-in",
|
|
84
|
+
"drop-shadow()": "drop-shadow( [ <color>? && <length>{2,3} ] )",
|
|
85
|
+
"element()": "element( <custom-ident> , [ first | start | last | first-except ]? ) | element( <id-selector> )",
|
|
86
|
+
"ellipse()": "ellipse( <radial-size>? [ at <position> ]? )",
|
|
87
|
+
"family-name": "<string> | <custom-ident>+",
|
|
88
|
+
"filter-function": "<blur()> | <brightness()> | <contrast()> | <drop-shadow()> | <grayscale()> | <hue-rotate()> | <invert()> | <opacity()> | <saturate()> | <sepia()>",
|
|
89
|
+
"filter-value-list": "[ <filter-function> | <url> ]+",
|
|
90
|
+
"final-bg-layer": "<bg-image> || <bg-position> [ / <bg-size> ]? || <repeat-style> || <attachment> || <visual-box> || <visual-box> || <'background-color'>",
|
|
91
|
+
"font-variant-css2": "normal | small-caps",
|
|
92
|
+
"font-weight-absolute": "normal | bold | <number [1,1000]>",
|
|
93
|
+
"font-width-css3": "normal | ultra-condensed | extra-condensed | condensed | semi-condensed | semi-expanded | expanded | extra-expanded | ultra-expanded",
|
|
94
|
+
"generic-complete": "serif | sans-serif | system-ui | cursive | fantasy | math | monospace",
|
|
95
|
+
"generic-family": "<generic-script-specific>| <generic-complete> | <generic-incomplete> | <-non-standard-generic-family>",
|
|
96
|
+
"generic-incomplete": "ui-serif | ui-sans-serif | ui-monospace | ui-rounded",
|
|
97
|
+
"generic-script-specific": "generic(kai) | generic(fangsong) | generic(nastaliq)",
|
|
98
|
+
"geometry-box": "<shape-box> | fill-box | stroke-box | view-box",
|
|
99
|
+
"gradient": "<linear-gradient()> | <repeating-linear-gradient()> | <radial-gradient()> | <repeating-radial-gradient()> | <conic-gradient()> | <repeating-conic-gradient()> | <-legacy-gradient>",
|
|
100
|
+
"grayscale()": "grayscale( [ <number> | <percentage> ]? )",
|
|
101
|
+
"hsl()": "hsl( <hue>, <percentage>, <percentage>, <alpha-value>? ) | hsl( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? )",
|
|
102
|
+
"hsla()": "hsla( <hue>, <percentage>, <percentage>, <alpha-value>? ) | hsla( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? )",
|
|
103
|
+
"hue": "<number> | <angle>",
|
|
104
|
+
"hue-interpolation-method": "[ shorter | longer | increasing | decreasing ] hue",
|
|
105
|
+
"hue-rotate()": "hue-rotate( [ <angle> | <zero> ]? )",
|
|
106
|
+
"hwb()": "hwb( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? )",
|
|
107
|
+
"id-selector": "<hash-token>",
|
|
108
|
+
"image()": "image( <image-tags>? [ <image-src>? , <color>? ]! )",
|
|
109
|
+
"image": "<url> | <image()> | <image-set()> | <element()> | <paint()> | <cross-fade()> | <gradient>",
|
|
110
|
+
"image-set()": "image-set( <image-set-option># )",
|
|
111
|
+
"image-set-option": "[ <image> | <string> ] [ <resolution> || type(<string>) ]",
|
|
112
|
+
"image-src": "<url> | <string>",
|
|
113
|
+
"image-tags": "ltr | rtl",
|
|
114
|
+
"inset()": "inset( <length-percentage>{1,4} [ round <'border-radius'> ]? )",
|
|
115
|
+
"intrinsic-size-keyword": "min-content | max-content | fit-content",
|
|
116
|
+
"invert()": "invert( [ <number> | <percentage> ]? )",
|
|
117
|
+
"lab()": "lab( [<percentage> | <number> | none] [ <percentage> | <number> | none] [ <percentage> | <number> | none] [ / [<alpha-value> | none] ]? )",
|
|
118
|
+
"lch()": "lch( [<percentage> | <number> | none] [ <percentage> | <number> | none] [ <hue> | none] [ / [<alpha-value> | none] ]? )",
|
|
119
|
+
"left": "<length> | auto",
|
|
120
|
+
"legacy-device-cmyk-syntax": "device-cmyk( <number>#{4} )",
|
|
121
|
+
"length-percentage": "<length> | <percentage>",
|
|
122
|
+
"light-dark()": "light-dark( <color>, <color> )",
|
|
123
|
+
"line-style": "none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset",
|
|
124
|
+
"line-width": "<length> | thin | medium | thick",
|
|
125
|
+
"linear-color-hint": "<length-percentage>",
|
|
126
|
+
"linear-color-stop": "<color> <color-stop-length>?",
|
|
127
|
+
"linear-gradient()": "linear-gradient( [ <linear-gradient-syntax> ] )",
|
|
128
|
+
"linear-gradient-syntax": "[ [ <angle> | <zero> | to <side-or-corner> ] || <color-interpolation-method> ]? , <color-stop-list>",
|
|
129
|
+
"matrix()": "matrix( <number>#{6} )",
|
|
130
|
+
"matrix3d()": "matrix3d( <number>#{16} )",
|
|
131
|
+
"modern-device-cmyk-syntax": "device-cmyk( <cmyk-component>{4} [ / [ <alpha-value> | none ] ]? )",
|
|
132
|
+
"named-color": "aliceblue | antiquewhite | aqua | aquamarine | azure | beige | bisque | black | blanchedalmond | blue | blueviolet | brown | burlywood | cadetblue | chartreuse | chocolate | coral | cornflowerblue | cornsilk | crimson | cyan | darkblue | darkcyan | darkgoldenrod | darkgray | darkgreen | darkgrey | darkkhaki | darkmagenta | darkolivegreen | darkorange | darkorchid | darkred | darksalmon | darkseagreen | darkslateblue | darkslategray | darkslategrey | darkturquoise | darkviolet | deeppink | deepskyblue | dimgray | dimgrey | dodgerblue | firebrick | floralwhite | forestgreen | fuchsia | gainsboro | ghostwhite | gold | goldenrod | gray | green | greenyellow | grey | honeydew | hotpink | indianred | indigo | ivory | khaki | lavender | lavenderblush | lawngreen | lemonchiffon | lightblue | lightcoral | lightcyan | lightgoldenrodyellow | lightgray | lightgreen | lightgrey | lightpink | lightsalmon | lightseagreen | lightskyblue | lightslategray | lightslategrey | lightsteelblue | lightyellow | lime | limegreen | linen | magenta | maroon | mediumaquamarine | mediumblue | mediumorchid | mediumpurple | mediumseagreen | mediumslateblue | mediumspringgreen | mediumturquoise | mediumvioletred | midnightblue | mintcream | mistyrose | moccasin | navajowhite | navy | oldlace | olive | olivedrab | orange | orangered | orchid | palegoldenrod | palegreen | paleturquoise | palevioletred | papayawhip | peachpuff | peru | pink | plum | powderblue | purple | rebeccapurple | red | rosybrown | royalblue | saddlebrown | salmon | sandybrown | seagreen | seashell | sienna | silver | skyblue | slateblue | slategray | slategrey | snow | springgreen | steelblue | tan | teal | thistle | tomato | turquoise | violet | wheat | white | whitesmoke | yellow | yellowgreen",
|
|
133
|
+
"number-zero-one": "<number [0,1]>",
|
|
134
|
+
"oklab()": "oklab( [ <percentage> | <number> | none] [ <percentage> | <number> | none] [ <percentage> | <number> | none] [ / [<alpha-value> | none] ]? )",
|
|
135
|
+
"oklch()": "oklch( [ <percentage> | <number> | none] [ <percentage> | <number> | none] [ <hue> | none] [ / [<alpha-value> | none] ]? )",
|
|
136
|
+
"opacity()": "opacity( [ <number> | <percentage> ]? )",
|
|
137
|
+
"opacity-value": "<number> | <percentage>",
|
|
138
|
+
"paint()": "paint( <ident>, <declaration-value>? )",
|
|
139
|
+
"path()": "path( <'fill-rule'>? , <string> )",
|
|
140
|
+
"perspective()": "perspective( [ <length [0,∞]> | none ] )",
|
|
141
|
+
"polar-color-space": "hsl | hwb | lch | oklch",
|
|
142
|
+
"polygon()": "polygon( <'fill-rule'>? , [ <length-percentage> <length-percentage> ]# )",
|
|
143
|
+
"position": "[ [ left | center | right ] || [ top | center | bottom ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ]? | [ [ left | right ] <length-percentage> ] && [ [ top | bottom ] <length-percentage> ] ]",
|
|
144
|
+
"predefined-rgb": "srgb | srgb-linear | display-p3 | display-p3-linear | a98-rgb | prophoto-rgb | rec2020",
|
|
145
|
+
"predefined-rgb-params": "<predefined-rgb> [ <number> | <percentage> | none ]{3}",
|
|
146
|
+
"radial-extent": "closest-corner | closest-side | farthest-corner | farthest-side",
|
|
147
|
+
"radial-gradient()": "radial-gradient( [ <radial-gradient-syntax> ] )",
|
|
148
|
+
"radial-gradient-syntax": "[ [ [ <radial-shape> || <radial-size> ]? [ at <position> ]? ] || <color-interpolation-method> ]? , <color-stop-list>",
|
|
149
|
+
"radial-shape": "circle | ellipse",
|
|
150
|
+
"radial-size": "<radial-extent> | <length [0,∞]> | <length-percentage [0,∞]>{2}",
|
|
151
|
+
"rect()": "rect( [ <length-percentage> | auto ]{4} [ round <'border-radius'> ]? )",
|
|
152
|
+
"rectangular-color-space": "srgb | srgb-linear | display-p3 | display-p3-linear | a98-rgb | prophoto-rgb | rec2020 | lab | oklab | xyz | xyz-d50 | xyz-d65",
|
|
153
|
+
"relative-size": "larger | smaller",
|
|
154
|
+
"repeat-style": "repeat-x | repeat-y | [ repeat | space | round | no-repeat ]{1,2}",
|
|
155
|
+
"repeating-conic-gradient()": "repeating-conic-gradient( [ <conic-gradient-syntax> ] )",
|
|
156
|
+
"repeating-linear-gradient()": "repeating-linear-gradient( [ <linear-gradient-syntax> ] )",
|
|
157
|
+
"repeating-radial-gradient()": "repeating-radial-gradient( [ <radial-gradient-syntax> ] )",
|
|
158
|
+
"rgb()": "rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? ) | rgb( [ <number> | <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? )",
|
|
159
|
+
"rgba()": "rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? ) | rgba( [ <number> | <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? )",
|
|
160
|
+
"right": "<length> | auto",
|
|
161
|
+
"rotate()": "rotate( [ <angle> | <zero> ] )",
|
|
162
|
+
"rotate3d()": "rotate3d( <number> , <number> , <number> , [ <angle> | <zero> ] )",
|
|
163
|
+
"rotateX()": "rotateX( [ <angle> | <zero> ] )",
|
|
164
|
+
"rotateY()": "rotateY( [ <angle> | <zero> ] )",
|
|
165
|
+
"rotateZ()": "rotateZ( [ <angle> | <zero> ] )",
|
|
166
|
+
"saturate()": "saturate( [ <number> | <percentage> ]? )",
|
|
167
|
+
"scale()": "scale( [ <number> | <percentage> ]#{1,2} )",
|
|
168
|
+
"scale3d()": "scale3d( [ <number> | <percentage> ]#{3} )",
|
|
169
|
+
"scaleX()": "scaleX( [ <number> | <percentage> ] )",
|
|
170
|
+
"scaleY()": "scaleY( [ <number> | <percentage> ] )",
|
|
171
|
+
"scaleZ()": "scaleZ( [ <number> | <percentage> ] )",
|
|
172
|
+
"sepia()": "sepia( [ <number> | <percentage> ]? )",
|
|
173
|
+
"shape": "rect( <top>, <right>, <bottom>, <left> ) | rect( <top> <right> <bottom> <left> )",
|
|
174
|
+
"shape-box": "<visual-box> | margin-box",
|
|
175
|
+
"side-or-corner": "[ left | right ] || [ top | bottom ]",
|
|
176
|
+
"skew()": "skew( [ <angle> | <zero> ] , [ <angle> | <zero> ]? )",
|
|
177
|
+
"skewX()": "skewX( [ <angle> | <zero> ] )",
|
|
178
|
+
"skewY()": "skewY( [ <angle> | <zero> ] )",
|
|
179
|
+
"system-color": "AccentColor | AccentColorText | ActiveText | ButtonBorder | ButtonFace | ButtonText | Canvas | CanvasText | Field | FieldText | GrayText | Highlight | HighlightText | LinkText | Mark | MarkText | SelectedItem | SelectedItemText | VisitedText",
|
|
180
|
+
"system-family-name": "caption | icon | menu | message-box | small-caption | status-bar",
|
|
181
|
+
"top": "<length> | auto",
|
|
182
|
+
"transform-function": "<matrix()> | <translate()> | <translateX()> | <translateY()> | <scale()> | <scaleX()> | <scaleY()> | <rotate()> | <skew()> | <skewX()> | <skewY()> | <matrix3d()> | <translate3d()> | <translateZ()> | <scale3d()> | <scaleZ()> | <rotate3d()> | <rotateX()> | <rotateY()> | <rotateZ()> | <perspective()>",
|
|
183
|
+
"transform-list": "<transform-function>+",
|
|
184
|
+
"translate()": "translate( <length-percentage> , <length-percentage>? )",
|
|
185
|
+
"translate3d()": "translate3d( <length-percentage> , <length-percentage> , <length> )",
|
|
186
|
+
"translateX()": "translateX( <length-percentage> )",
|
|
187
|
+
"translateY()": "translateY( <length-percentage> )",
|
|
188
|
+
"translateZ()": "translateZ( <length> )",
|
|
189
|
+
"url": "url( <string> <url-modifier>* ) | <url-token>",
|
|
190
|
+
"url-modifier": "<ident> | <function-token> <any-value> )",
|
|
191
|
+
"visual-box": "content-box | padding-box | border-box",
|
|
192
|
+
"xywh()": "xywh( <length-percentage>{2} <length-percentage [0,∞]>{2} [ round <'border-radius'> ]? )",
|
|
193
|
+
"xyz-params": "<xyz-space> [ <number> | <percentage> | none ]{3}",
|
|
194
|
+
"xyz-space": "xyz | xyz-d50 | xyz-d65",
|
|
195
|
+
},
|
|
196
|
+
properties: {
|
|
197
|
+
"-webkit-background-clip": "[ <visual-box> | border | padding | content | text ]#",
|
|
198
|
+
"-webkit-text-fill-color": "<color>",
|
|
199
|
+
"-webkit-text-stroke": "<length> || <color>",
|
|
200
|
+
"-webkit-text-stroke-color": "<color>",
|
|
201
|
+
"all": "initial | inherit | unset | revert | revert-layer",
|
|
202
|
+
"background": "<bg-layer>#? , <final-bg-layer>",
|
|
203
|
+
"background-clip": "<bg-clip>#",
|
|
204
|
+
"background-color": "<color>",
|
|
205
|
+
"background-image": "<bg-image>#",
|
|
206
|
+
"border": "<line-width> || <line-style> || <color>",
|
|
207
|
+
"border-block": "<'border-block-start'>",
|
|
208
|
+
"border-block-end": "<'border-top-width'> || <'border-top-style'> || <color>",
|
|
209
|
+
"border-block-end-width": "<'border-top-width'>",
|
|
210
|
+
"border-block-start": "<'border-top-width'> || <'border-top-style'> || <color>",
|
|
211
|
+
"border-block-start-width": "<'border-top-width'>",
|
|
212
|
+
"border-block-width": "<'border-top-width'>{1,2}",
|
|
213
|
+
"border-bottom": "<line-width> || <line-style> || <color>",
|
|
214
|
+
"border-bottom-width": "<line-width>",
|
|
215
|
+
"border-inline": "<'border-block-start'>",
|
|
216
|
+
"border-inline-end": "<'border-top-width'> || <'border-top-style'> || <color>",
|
|
217
|
+
"border-inline-end-width": "<'border-top-width'>",
|
|
218
|
+
"border-inline-start": "<'border-top-width'> || <'border-top-style'> || <color>",
|
|
219
|
+
"border-inline-start-width": "<'border-top-width'>",
|
|
220
|
+
"border-inline-width": "<'border-top-width'>{1,2}",
|
|
221
|
+
"border-left": "<line-width> || <line-style> || <color>",
|
|
222
|
+
"border-left-width": "<line-width>",
|
|
223
|
+
"border-radius": "<length-percentage [0,∞]>{1,4} [ / <length-percentage [0,∞]>{1,4} ]?",
|
|
224
|
+
"border-right": "<line-width> || <line-style> || <color>",
|
|
225
|
+
"border-right-width": "<line-width>",
|
|
226
|
+
"border-top": "<line-width> || <line-style> || <color>",
|
|
227
|
+
"border-top-style": "<line-style>",
|
|
228
|
+
"border-top-width": "<line-width>",
|
|
229
|
+
"border-width": "<line-width>{1,4}",
|
|
230
|
+
"bottom": "auto | <length-percentage> | <anchor()> | <anchor-size()>",
|
|
231
|
+
"clip": "<shape> | auto",
|
|
232
|
+
"clip-path": "<clip-source> | [ <basic-shape> || <geometry-box> ] | none",
|
|
233
|
+
"color": "<color>",
|
|
234
|
+
"content-visibility": "visible | auto | hidden",
|
|
235
|
+
"display": "[ <display-outside> || <display-inside> ] | <display-listitem> | <display-internal> | <display-box> | <display-legacy> | <-non-standard-display>",
|
|
236
|
+
"fill-rule": "nonzero | evenodd",
|
|
237
|
+
"filter": "none | <filter-value-list> | <-ms-filter-function-list>",
|
|
238
|
+
"float": "left | right | none | inline-start | inline-end",
|
|
239
|
+
"font": "[ [ <'font-style'> || <font-variant-css2> || <'font-weight'> || <font-width-css3> ]? <'font-size'> [ / <'line-height'> ]? <'font-family'># ] | <system-family-name> | <-non-standard-font>",
|
|
240
|
+
"font-family": "[ <family-name> | <generic-family> ]#",
|
|
241
|
+
"font-size": "<absolute-size> | <relative-size> | <length-percentage [0,∞]> | math",
|
|
242
|
+
"font-style": "normal | italic | oblique <angle>?",
|
|
243
|
+
"font-weight": "<font-weight-absolute> | bolder | lighter",
|
|
244
|
+
"height": "auto | <length-percentage [0,∞]> | min-content | max-content | fit-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> | <anchor-size()> | stretch | <-non-standard-size>",
|
|
245
|
+
"inset": "<'top'>{1,4}",
|
|
246
|
+
"left": "auto | <length-percentage> | <anchor()> | <anchor-size()>",
|
|
247
|
+
"line-height": "normal | <number> | <length> | <percentage>",
|
|
248
|
+
"max-height": "none | <length-percentage [0,∞]> | min-content | max-content | fit-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> | <anchor-size()> | stretch | <-non-standard-size>",
|
|
249
|
+
"max-width": "none | <length-percentage [0,∞]> | min-content | max-content | fit-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> | <anchor-size()> | stretch | <-non-standard-size>",
|
|
250
|
+
"opacity": "<opacity-value>",
|
|
251
|
+
"overflow": "[ visible | hidden | clip | scroll | auto ]{1,2} | <-non-standard-overflow>",
|
|
252
|
+
"padding": "<'padding-top'>{1,4}",
|
|
253
|
+
"padding-block": "<'padding-top'>{1,2}",
|
|
254
|
+
"padding-block-end": "<'padding-top'>",
|
|
255
|
+
"padding-block-start": "<'padding-top'>",
|
|
256
|
+
"padding-bottom": "<length-percentage [0,∞]>",
|
|
257
|
+
"padding-inline": "<'padding-top'>{1,2}",
|
|
258
|
+
"padding-inline-end": "<'padding-top'>",
|
|
259
|
+
"padding-inline-start": "<'padding-top'>",
|
|
260
|
+
"padding-left": "<length-percentage [0,∞]>",
|
|
261
|
+
"padding-right": "<length-percentage [0,∞]>",
|
|
262
|
+
"padding-top": "<length-percentage [0,∞]>",
|
|
263
|
+
"position": "static | relative | absolute | sticky | fixed | -webkit-sticky",
|
|
264
|
+
"right": "auto | <length-percentage> | <anchor()> | <anchor-size()>",
|
|
265
|
+
"text-indent": "<length-percentage> && hanging? && each-line?",
|
|
266
|
+
"top": "auto | <length-percentage> | <anchor()> | <anchor-size()>",
|
|
267
|
+
"transform": "none | <transform-list>",
|
|
268
|
+
"translate": "none | <length-percentage> [ <length-percentage> <length>? ]?",
|
|
269
|
+
"visibility": "visible | hidden | collapse",
|
|
270
|
+
"width": "auto | <length-percentage [0,∞]> | min-content | max-content | fit-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> | <anchor-size()> | stretch | <-non-standard-size>",
|
|
271
|
+
"x": "<length> | <percentage>",
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
// Stryker restore all
|
|
@@ -139,5 +139,117 @@ export function parseHtmlFragment(html) {
|
|
|
139
139
|
treeAdapter: adapter,
|
|
140
140
|
});
|
|
141
141
|
settle();
|
|
142
|
-
return
|
|
142
|
+
return fromParse5Bounded(fragment, new VFile(html));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* How many levels of the tree one `fromParse5` call converts.
|
|
147
|
+
*
|
|
148
|
+
* WHY IT EXISTS — `hast-util-from-parse5` converts by recursion, three frames
|
|
149
|
+
* (`one` → `all` → `element`) per level, so how deep a tree it survives is
|
|
150
|
+
* whatever stack is left, and that depends on the JIT tier: a cold call's
|
|
151
|
+
* interpreted frames are bigger than an optimized one's. ~2500 nested elements
|
|
152
|
+
* overflowed on the first call in a process and converted fine on a later one,
|
|
153
|
+
* so the same document came back withheld or sanitized depending on what had
|
|
154
|
+
* run before it. 128 levels still convert cold on a 100 KB stack, a tenth of
|
|
155
|
+
* Node's default.
|
|
156
|
+
*/
|
|
157
|
+
export const CONVERT_DEPTH = 128;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The deepest a node may sit below the fragment root; a deeper parse throws, so
|
|
161
|
+
* the caller fails closed on it.
|
|
162
|
+
*
|
|
163
|
+
* Conversion no longer limits depth (see {@link CONVERT_DEPTH}), so this is the
|
|
164
|
+
* one place that does, and it answers the same way at every JIT tier. No real
|
|
165
|
+
* document comes near it — Blink's parser flattens anything nested past 512 —
|
|
166
|
+
* and what lies past it is built to cost: parse5's scope checks walk the
|
|
167
|
+
* open-element stack per tag, so parsing is quadratic in depth.
|
|
168
|
+
*/
|
|
169
|
+
export const MAX_HTML_DEPTH = 4096;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* `fromParse5(tree, { file })`, recursing at most `chunkDepth` levels at a time.
|
|
173
|
+
*
|
|
174
|
+
* Every node a multiple of `chunkDepth` levels down is converted on its own,
|
|
175
|
+
* deepest first, and then stands in its parent's `childNodes` as a placeholder
|
|
176
|
+
* text node carrying the converted subtree's position — the one thing about a
|
|
177
|
+
* child its parent's conversion reads (an unclosed element ends where its last
|
|
178
|
+
* child does). One walk then swaps each placeholder for its subtree. The result
|
|
179
|
+
* is the tree a single `fromParse5` call returns, which
|
|
180
|
+
* `html-tree-adapter.test` holds it to.
|
|
181
|
+
*
|
|
182
|
+
* Mutates `tree`: {@link parseHtmlFragment} owns the parse and drops it after.
|
|
183
|
+
* @param {any} tree
|
|
184
|
+
* @param {VFile} file
|
|
185
|
+
* @param {number} [chunkDepth]
|
|
186
|
+
* @returns {any}
|
|
187
|
+
*/
|
|
188
|
+
export function fromParse5Bounded(tree, file, chunkDepth = CONVERT_DEPTH) {
|
|
189
|
+
/** @type {Array<{ siblings: any[], index: number }>} */
|
|
190
|
+
const cuts = [];
|
|
191
|
+
const stack = [{ node: tree, depth: 0 }];
|
|
192
|
+
while (stack.length > 0) {
|
|
193
|
+
const { node, depth } = /** @type {{ node: any, depth: number }} */ (
|
|
194
|
+
stack.pop()
|
|
195
|
+
);
|
|
196
|
+
if (depth > MAX_HTML_DEPTH)
|
|
197
|
+
throw new RangeError(`HTML nested deeper than ${MAX_HTML_DEPTH} levels`);
|
|
198
|
+
// A template's content is a root its template's conversion recurses into.
|
|
199
|
+
if (node.content) stack.push({ node: node.content, depth: depth + 1 });
|
|
200
|
+
const siblings = node.childNodes ?? [];
|
|
201
|
+
const childDepth = depth + 1;
|
|
202
|
+
for (let index = 0; index < siblings.length; index++) {
|
|
203
|
+
if (childDepth % chunkDepth === 0) cuts.push({ siblings, index });
|
|
204
|
+
stack.push({ node: siblings[index], depth: childDepth });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// The walk reaches a cut before any cut below it, so going backwards converts
|
|
208
|
+
// a subtree only once everything cut out of it already stands as a
|
|
209
|
+
// placeholder.
|
|
210
|
+
const grafts = new Map();
|
|
211
|
+
for (let i = cuts.length - 1; i >= 0; i--) {
|
|
212
|
+
const { siblings, index } = cuts[i];
|
|
213
|
+
const converted = fromParse5(siblings[index], { file });
|
|
214
|
+
const token = {};
|
|
215
|
+
grafts.set(token, converted);
|
|
216
|
+
siblings[index] = {
|
|
217
|
+
nodeName: "#text",
|
|
218
|
+
value: token,
|
|
219
|
+
sourceCodeLocation: parse5Location(converted.position),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
const root = fromParse5(tree, { file });
|
|
223
|
+
/** @type {any[]} */
|
|
224
|
+
const pending = [root];
|
|
225
|
+
while (grafts.size > 0 && pending.length > 0) {
|
|
226
|
+
const node = pending.pop();
|
|
227
|
+
if (node.content) pending.push(node.content);
|
|
228
|
+
const children = node.children ?? [];
|
|
229
|
+
for (let i = 0; i < children.length; i++) {
|
|
230
|
+
children[i] = grafts.get(children[i].value) ?? children[i];
|
|
231
|
+
pending.push(children[i]);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return root;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* The parse5 location `hast-util-from-parse5` turns back into `position`.
|
|
239
|
+
*
|
|
240
|
+
* A position it built always has both points: it drops one only when parse5
|
|
241
|
+
* gave no line, and parse5 gives a location whole or not at all.
|
|
242
|
+
* @param {any} position
|
|
243
|
+
*/
|
|
244
|
+
function parse5Location(position) {
|
|
245
|
+
if (!position) return undefined;
|
|
246
|
+
const { start, end } = position;
|
|
247
|
+
return {
|
|
248
|
+
startLine: start.line,
|
|
249
|
+
startCol: start.column,
|
|
250
|
+
startOffset: start.offset,
|
|
251
|
+
endLine: end.line,
|
|
252
|
+
endCol: end.column,
|
|
253
|
+
endOffset: end.offset,
|
|
254
|
+
};
|
|
143
255
|
}
|