entities 7.0.0 → 8.0.0
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/dist/decode-codepoint.d.ts +8 -0
- package/dist/decode-codepoint.d.ts.map +1 -0
- package/dist/decode-codepoint.js +46 -0
- package/dist/decode-codepoint.js.map +1 -0
- package/dist/{commonjs/decode.d.ts → decode.d.ts} +11 -20
- package/dist/decode.d.ts.map +1 -0
- package/dist/{esm/decode.js → decode.js} +65 -75
- package/dist/decode.js.map +1 -0
- package/dist/{commonjs/encode.d.ts → encode.d.ts} +2 -0
- package/dist/encode.d.ts.map +1 -0
- package/dist/{esm/encode.js → encode.js} +6 -4
- package/dist/encode.js.map +1 -0
- package/dist/{esm/escape.d.ts → escape.d.ts} +6 -4
- package/dist/escape.d.ts.map +1 -0
- package/dist/{esm/escape.js → escape.js} +15 -17
- package/dist/escape.js.map +1 -0
- package/dist/generated/decode-data-html.d.ts +3 -0
- package/dist/generated/decode-data-html.d.ts.map +1 -0
- package/dist/{esm/generated → generated}/decode-data-html.js +1 -0
- package/dist/generated/decode-data-html.js.map +1 -0
- package/dist/generated/decode-data-xml.d.ts +3 -0
- package/dist/generated/decode-data-xml.d.ts.map +1 -0
- package/dist/{esm/generated → generated}/decode-data-xml.js +1 -0
- package/dist/generated/decode-data-xml.js.map +1 -0
- package/dist/generated/encode-html.d.ts +5 -0
- package/dist/generated/encode-html.d.ts.map +1 -0
- package/dist/{esm/generated → generated}/encode-html.js +2 -1
- package/dist/generated/encode-html.js.map +1 -0
- package/dist/{commonjs/index.d.ts → index.d.ts} +9 -16
- package/dist/index.d.ts.map +1 -0
- package/dist/{esm/index.js → index.js} +7 -23
- package/dist/index.js.map +1 -0
- package/dist/internal/bin-trie-flags.d.ts.map +1 -0
- package/dist/internal/bin-trie-flags.js.map +1 -0
- package/dist/internal/decode-shared.d.ts +7 -0
- package/dist/internal/decode-shared.d.ts.map +1 -0
- package/dist/internal/decode-shared.js +17 -0
- package/dist/internal/decode-shared.js.map +1 -0
- package/dist/{commonjs/internal → internal}/encode-shared.d.ts +1 -0
- package/dist/internal/encode-shared.d.ts.map +1 -0
- package/dist/{esm/internal → internal}/encode-shared.js +4 -2
- package/dist/internal/encode-shared.js.map +1 -0
- package/package.json +33 -63
- package/readme.md +36 -27
- package/src/decode-codepoint.ts +1 -32
- package/src/decode.ts +49 -54
- package/src/encode.ts +2 -0
- package/src/escape.ts +11 -12
- package/src/generated/decode-data-html.ts +1 -0
- package/src/generated/decode-data-xml.ts +1 -0
- package/src/generated/encode-html.ts +2 -1
- package/src/index.ts +8 -33
- package/src/internal/decode-shared.ts +3 -15
- package/src/internal/encode-shared.ts +4 -2
- package/decode.d.ts +0 -3
- package/decode.js +0 -3
- package/dist/commonjs/decode-codepoint.d.ts +0 -19
- package/dist/commonjs/decode-codepoint.d.ts.map +0 -1
- package/dist/commonjs/decode-codepoint.js +0 -77
- package/dist/commonjs/decode-codepoint.js.map +0 -1
- package/dist/commonjs/decode.d.ts.map +0 -1
- package/dist/commonjs/decode.js +0 -568
- package/dist/commonjs/decode.js.map +0 -1
- package/dist/commonjs/encode.d.ts.map +0 -1
- package/dist/commonjs/encode.js +0 -92
- package/dist/commonjs/encode.js.map +0 -1
- package/dist/commonjs/escape.d.ts +0 -46
- package/dist/commonjs/escape.d.ts.map +0 -1
- package/dist/commonjs/escape.js +0 -138
- package/dist/commonjs/escape.js.map +0 -1
- package/dist/commonjs/generated/decode-data-html.d.ts +0 -2
- package/dist/commonjs/generated/decode-data-html.d.ts.map +0 -1
- package/dist/commonjs/generated/decode-data-html.js +0 -7
- package/dist/commonjs/generated/decode-data-html.js.map +0 -1
- package/dist/commonjs/generated/decode-data-xml.d.ts +0 -2
- package/dist/commonjs/generated/decode-data-xml.d.ts.map +0 -1
- package/dist/commonjs/generated/decode-data-xml.js +0 -7
- package/dist/commonjs/generated/decode-data-xml.js.map +0 -1
- package/dist/commonjs/generated/encode-html.d.ts +0 -3
- package/dist/commonjs/generated/encode-html.d.ts.map +0 -1
- package/dist/commonjs/generated/encode-html.js +0 -14
- package/dist/commonjs/generated/encode-html.js.map +0 -1
- package/dist/commonjs/index.d.ts.map +0 -1
- package/dist/commonjs/index.js +0 -131
- package/dist/commonjs/index.js.map +0 -1
- package/dist/commonjs/internal/bin-trie-flags.d.ts.map +0 -1
- package/dist/commonjs/internal/bin-trie-flags.js +0 -21
- package/dist/commonjs/internal/bin-trie-flags.js.map +0 -1
- package/dist/commonjs/internal/decode-shared.d.ts +0 -2
- package/dist/commonjs/internal/decode-shared.d.ts.map +0 -1
- package/dist/commonjs/internal/decode-shared.js +0 -31
- package/dist/commonjs/internal/decode-shared.js.map +0 -1
- package/dist/commonjs/internal/encode-shared.d.ts.map +0 -1
- package/dist/commonjs/internal/encode-shared.js +0 -94
- package/dist/commonjs/internal/encode-shared.js.map +0 -1
- package/dist/commonjs/package.json +0 -3
- package/dist/esm/decode-codepoint.d.ts +0 -19
- package/dist/esm/decode-codepoint.d.ts.map +0 -1
- package/dist/esm/decode-codepoint.js +0 -72
- package/dist/esm/decode-codepoint.js.map +0 -1
- package/dist/esm/decode.d.ts +0 -203
- package/dist/esm/decode.d.ts.map +0 -1
- package/dist/esm/decode.js.map +0 -1
- package/dist/esm/encode.d.ts +0 -22
- package/dist/esm/encode.d.ts.map +0 -1
- package/dist/esm/encode.js.map +0 -1
- package/dist/esm/escape.d.ts.map +0 -1
- package/dist/esm/escape.js.map +0 -1
- package/dist/esm/generated/decode-data-html.d.ts +0 -2
- package/dist/esm/generated/decode-data-html.d.ts.map +0 -1
- package/dist/esm/generated/decode-data-html.js.map +0 -1
- package/dist/esm/generated/decode-data-xml.d.ts +0 -2
- package/dist/esm/generated/decode-data-xml.d.ts.map +0 -1
- package/dist/esm/generated/decode-data-xml.js.map +0 -1
- package/dist/esm/generated/encode-html.d.ts +0 -3
- package/dist/esm/generated/encode-html.d.ts.map +0 -1
- package/dist/esm/generated/encode-html.js.map +0 -1
- package/dist/esm/index.d.ts +0 -96
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/internal/bin-trie-flags.d.ts +0 -17
- package/dist/esm/internal/bin-trie-flags.d.ts.map +0 -1
- package/dist/esm/internal/bin-trie-flags.js.map +0 -1
- package/dist/esm/internal/decode-shared.d.ts +0 -2
- package/dist/esm/internal/decode-shared.d.ts.map +0 -1
- package/dist/esm/internal/decode-shared.js +0 -28
- package/dist/esm/internal/decode-shared.js.map +0 -1
- package/dist/esm/internal/encode-shared.d.ts +0 -32
- package/dist/esm/internal/encode-shared.d.ts.map +0 -1
- package/dist/esm/internal/encode-shared.js.map +0 -1
- package/dist/esm/package.json +0 -3
- package/escape.d.ts +0 -3
- package/escape.js +0 -3
- package/src/decode.spec.ts +0 -363
- package/src/encode.spec.ts +0 -78
- package/src/escape.spec.ts +0 -14
- package/src/generated/.eslintrc.json +0 -10
- package/src/index.spec.ts +0 -125
- /package/dist/{commonjs/internal → internal}/bin-trie-flags.d.ts +0 -0
- /package/dist/{esm/internal → internal}/bin-trie-flags.js +0 -0
package/dist/esm/index.d.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { DecodingMode } from "./decode.js";
|
|
2
|
-
/** The level of entities to support. */
|
|
3
|
-
export declare enum EntityLevel {
|
|
4
|
-
/** Support only XML entities. */
|
|
5
|
-
XML = 0,
|
|
6
|
-
/** Support HTML entities, which are a superset of XML entities. */
|
|
7
|
-
HTML = 1
|
|
8
|
-
}
|
|
9
|
-
export declare enum EncodingMode {
|
|
10
|
-
/**
|
|
11
|
-
* The output is UTF-8 encoded. Only characters that need escaping within
|
|
12
|
-
* XML will be escaped.
|
|
13
|
-
*/
|
|
14
|
-
UTF8 = 0,
|
|
15
|
-
/**
|
|
16
|
-
* The output consists only of ASCII characters. Characters that need
|
|
17
|
-
* escaping within HTML, and characters that aren't ASCII characters will
|
|
18
|
-
* be escaped.
|
|
19
|
-
*/
|
|
20
|
-
ASCII = 1,
|
|
21
|
-
/**
|
|
22
|
-
* Encode all characters that have an equivalent entity, as well as all
|
|
23
|
-
* characters that are not ASCII characters.
|
|
24
|
-
*/
|
|
25
|
-
Extensive = 2,
|
|
26
|
-
/**
|
|
27
|
-
* Encode all characters that have to be escaped in HTML attributes,
|
|
28
|
-
* following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
|
|
29
|
-
*/
|
|
30
|
-
Attribute = 3,
|
|
31
|
-
/**
|
|
32
|
-
* Encode all characters that have to be escaped in HTML text,
|
|
33
|
-
* following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
|
|
34
|
-
*/
|
|
35
|
-
Text = 4
|
|
36
|
-
}
|
|
37
|
-
export interface DecodingOptions {
|
|
38
|
-
/**
|
|
39
|
-
* The level of entities to support.
|
|
40
|
-
* @default {@link EntityLevel.XML}
|
|
41
|
-
*/
|
|
42
|
-
level?: EntityLevel;
|
|
43
|
-
/**
|
|
44
|
-
* Decoding mode. If `Legacy`, will support legacy entities not terminated
|
|
45
|
-
* with a semicolon (`;`).
|
|
46
|
-
*
|
|
47
|
-
* Always `Strict` for XML. For HTML, set this to `true` if you are parsing
|
|
48
|
-
* an attribute value.
|
|
49
|
-
*
|
|
50
|
-
* The deprecated `decodeStrict` function defaults this to `Strict`.
|
|
51
|
-
*
|
|
52
|
-
* @default {@link DecodingMode.Legacy}
|
|
53
|
-
*/
|
|
54
|
-
mode?: DecodingMode | undefined;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Decodes a string with entities.
|
|
58
|
-
*
|
|
59
|
-
* @param input String to decode.
|
|
60
|
-
* @param options Decoding options.
|
|
61
|
-
*/
|
|
62
|
-
export declare function decode(input: string, options?: DecodingOptions | EntityLevel): string;
|
|
63
|
-
/**
|
|
64
|
-
* Decodes a string with entities. Does not allow missing trailing semicolons for entities.
|
|
65
|
-
*
|
|
66
|
-
* @param input String to decode.
|
|
67
|
-
* @param options Decoding options.
|
|
68
|
-
* @deprecated Use `decode` with the `mode` set to `Strict`.
|
|
69
|
-
*/
|
|
70
|
-
export declare function decodeStrict(input: string, options?: DecodingOptions | EntityLevel): string;
|
|
71
|
-
/**
|
|
72
|
-
* Options for `encode`.
|
|
73
|
-
*/
|
|
74
|
-
export interface EncodingOptions {
|
|
75
|
-
/**
|
|
76
|
-
* The level of entities to support.
|
|
77
|
-
* @default {@link EntityLevel.XML}
|
|
78
|
-
*/
|
|
79
|
-
level?: EntityLevel;
|
|
80
|
-
/**
|
|
81
|
-
* Output format.
|
|
82
|
-
* @default {@link EncodingMode.Extensive}
|
|
83
|
-
*/
|
|
84
|
-
mode?: EncodingMode;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Encodes a string with entities.
|
|
88
|
-
*
|
|
89
|
-
* @param input String to encode.
|
|
90
|
-
* @param options Encoding options.
|
|
91
|
-
*/
|
|
92
|
-
export declare function encode(input: string, options?: EncodingOptions | EntityLevel): string;
|
|
93
|
-
export { DecodingMode, decodeHTML, decodeHTML as decodeHTML4, decodeHTML as decodeHTML5, decodeHTMLAttribute, decodeHTMLStrict, decodeHTMLStrict as decodeHTML4Strict, decodeHTMLStrict as decodeHTML5Strict, decodeXML, decodeXML as decodeXMLStrict, EntityDecoder, } from "./decode.js";
|
|
94
|
-
export { encodeHTML, encodeHTML as encodeHTML4, encodeHTML as encodeHTML5, encodeNonAsciiHTML, } from "./encode.js";
|
|
95
|
-
export { encodeXML, escape, escapeAttribute, escapeText, escapeUTF8, } from "./escape.js";
|
|
96
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyB,MAAM,aAAa,CAAC;AASlE,wCAAwC;AACxC,oBAAY,WAAW;IACnB,iCAAiC;IACjC,GAAG,IAAI;IACP,mEAAmE;IACnE,IAAI,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U,GACb,MAAM,aAAa,CAAC"}
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EACH,SAAS,EACT,eAAe,EACf,UAAU,EACV,UAAU,GACb,MAAM,aAAa,CAAC;AAErB,wCAAwC;AACxC,MAAM,CAAN,IAAY,WAKX;AALD,WAAY,WAAW;IACnB,iCAAiC;IACjC,2CAAO,CAAA;IACP,mEAAmE;IACnE,6CAAQ,CAAA;AACZ,CAAC,EALW,WAAW,KAAX,WAAW,QAKtB;AAED,MAAM,CAAN,IAAY,YA2BX;AA3BD,WAAY,YAAY;IACpB;;;OAGG;IACH,+CAAI,CAAA;IACJ;;;;OAIG;IACH,iDAAK,CAAA;IACL;;;OAGG;IACH,yDAAS,CAAA;IACT;;;OAGG;IACH,yDAAS,CAAA;IACT;;;OAGG;IACH,+CAAI,CAAA;AACR,CAAC,EA3BW,YAAY,KAAZ,YAAY,QA2BvB;AAsBD;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAClB,KAAa,EACb,UAAyC,WAAW,CAAC,GAAG;IAExD,MAAM,KAAK,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IAEpE,IAAI,KAAK,KAAK,WAAW,CAAC,IAAI,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;QACpE,OAAO,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,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C3B,CAAC;QACD,wGAAwG;QACxG,KAAK,YAAY,CAAC,SAAS,CAAC,CAAC,qDAAqD;QAClF,OAAO,CAAC,CAAC,CAAC;YACN,OAAO,KAAK,KAAK,WAAW,CAAC,IAAI;gBAC7B,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC;gBACnB,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;IACL,CAAC;AACL,CAAC;AAED,OAAO,EACH,YAAY,EACZ,UAAU;AACV,8BAA8B;AAC9B,UAAU,IAAI,WAAW,EACzB,UAAU,IAAI,WAAW,EACzB,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,IAAI,iBAAiB,EACrC,gBAAgB,IAAI,iBAAiB,EACrC,SAAS,EACT,SAAS,IAAI,eAAe,EAC5B,aAAa,GAChB,MAAM,aAAa,CAAC;AAErB,OAAO,EACH,UAAU;AACV,8BAA8B;AAC9B,UAAU,IAAI,WAAW,EACzB,UAAU,IAAI,WAAW,EACzB,kBAAkB,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EACH,SAAS,EACT,MAAM,EACN,eAAe,EACf,UAAU,EACV,UAAU,GACb,MAAM,aAAa,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bit flags & masks for the binary trie encoding used for entity decoding.
|
|
3
|
-
*
|
|
4
|
-
* Bit layout (16 bits total):
|
|
5
|
-
* 15..14 VALUE_LENGTH (+1 encoding; 0 => no value)
|
|
6
|
-
* 13 FLAG13. If valueLength>0: semicolon required flag (implicit ';').
|
|
7
|
-
* If valueLength==0: compact run flag.
|
|
8
|
-
* 12..7 BRANCH_LENGTH Branch length (0 => single branch in 6..0 if jumpOffset==char) OR run length (when compact run)
|
|
9
|
-
* 6..0 JUMP_TABLE Jump offset (jump table) OR single-branch char code OR first run char
|
|
10
|
-
*/
|
|
11
|
-
export declare enum BinTrieFlags {
|
|
12
|
-
VALUE_LENGTH = 49152,
|
|
13
|
-
FLAG13 = 8192,
|
|
14
|
-
BRANCH_LENGTH = 8064,
|
|
15
|
-
JUMP_TABLE = 127
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=bin-trie-flags.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bin-trie-flags.d.ts","sourceRoot":"","sources":["../../../src/internal/bin-trie-flags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,oBAAY,YAAY;IACpB,YAAY,QAAwB;IACpC,MAAM,OAAwB;IAC9B,aAAa,OAAwB;IACrC,UAAU,MAAwB;CACrC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bin-trie-flags.js","sourceRoot":"","sources":["../../../src/internal/bin-trie-flags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAN,IAAY,YAKX;AALD,WAAY,YAAY;IACpB,mEAAoC,CAAA;IACpC,sDAA8B,CAAA;IAC9B,oEAAqC,CAAA;IACrC,6DAAkC,CAAA;AACtC,CAAC,EALW,YAAY,KAAZ,YAAY,QAKvB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decode-shared.d.ts","sourceRoot":"","sources":["../../../src/internal/decode-shared.ts"],"names":[],"mappings":"AAIA,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAyBvD"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Shared base64 decode helper for generated decode data.
|
|
3
|
-
* Assumes global atob is available.
|
|
4
|
-
*/
|
|
5
|
-
export function decodeBase64(input) {
|
|
6
|
-
const binary =
|
|
7
|
-
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
|
8
|
-
typeof atob === "function"
|
|
9
|
-
? // Browser (and Node >=16)
|
|
10
|
-
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
|
11
|
-
atob(input)
|
|
12
|
-
: // Older Node versions (<16)
|
|
13
|
-
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
|
14
|
-
typeof Buffer.from === "function"
|
|
15
|
-
? // eslint-disable-next-line n/no-unsupported-features/node-builtins
|
|
16
|
-
Buffer.from(input, "base64").toString("binary")
|
|
17
|
-
: // eslint-disable-next-line unicorn/no-new-buffer, n/no-deprecated-api
|
|
18
|
-
new Buffer(input, "base64").toString("binary");
|
|
19
|
-
const evenLength = binary.length & ~1; // Round down to even length
|
|
20
|
-
const out = new Uint16Array(evenLength / 2);
|
|
21
|
-
for (let index = 0, outIndex = 0; index < evenLength; index += 2) {
|
|
22
|
-
const lo = binary.charCodeAt(index);
|
|
23
|
-
const hi = binary.charCodeAt(index + 1);
|
|
24
|
-
out[outIndex++] = lo | (hi << 8);
|
|
25
|
-
}
|
|
26
|
-
return out;
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=decode-shared.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decode-shared.js","sourceRoot":"","sources":["../../../src/internal/decode-shared.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IACtC,MAAM,MAAM;IACR,mEAAmE;IACnE,OAAO,IAAI,KAAK,UAAU;QACtB,CAAC,CAAC,0BAA0B;YAC1B,mEAAmE;YACnE,IAAI,CAAC,KAAK,CAAC;QACb,CAAC,CAAC,4BAA4B;YAC5B,mEAAmE;YACnE,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU;gBACjC,CAAC,CAAC,mEAAmE;oBACnE,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBACjD,CAAC,CAAC,sEAAsE;oBACtE,IAAI,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE3D,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,4BAA4B;IACnE,MAAM,GAAG,GAAG,IAAI,WAAW,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;IAE5C,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,QAAQ,GAAG,CAAC,EAAE,KAAK,GAAG,UAAU,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QAC/D,MAAM,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACpC,MAAM,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QACxC,GAAG,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,OAAO,GAAG,CAAC;AACf,CAAC"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A node inside the encoding trie used by `encode.ts`.
|
|
3
|
-
*
|
|
4
|
-
* There are two physical shapes to minimize allocations and lookup cost:
|
|
5
|
-
*
|
|
6
|
-
* 1. Leaf node (string)
|
|
7
|
-
* - A plain string (already in the form `"&name;"`).
|
|
8
|
-
* - Represents a terminal match with no children.
|
|
9
|
-
*
|
|
10
|
-
* 2. Branch / value node (object)
|
|
11
|
-
*/
|
|
12
|
-
export type EncodeTrieNode = string | {
|
|
13
|
-
/**
|
|
14
|
-
* Entity value for the current code point sequence (wrapped: `&...;`).
|
|
15
|
-
* Present when the path to this node itself is a valid named entity.
|
|
16
|
-
*/
|
|
17
|
-
value: string | undefined;
|
|
18
|
-
/** If a number, the next code unit of the only next character. */
|
|
19
|
-
next: number | Map<number, EncodeTrieNode>;
|
|
20
|
-
/** If next is a number, `nextValue` contains the entity value. */
|
|
21
|
-
nextValue?: string;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Parse a compact encode trie string into a Map structure used for encoding.
|
|
25
|
-
*
|
|
26
|
-
* Format per entry (ascending code points using delta encoding):
|
|
27
|
-
* <diffBase36>[&name;][{<children>}] -- diff omitted when 0
|
|
28
|
-
* Where diff = currentKey - previousKey - 1 (first entry stores absolute key).
|
|
29
|
-
* `&name;` is the entity value (already wrapped); a following `{` denotes children.
|
|
30
|
-
*/
|
|
31
|
-
export declare function parseEncodeTrie(serialized: string): Map<number, EncodeTrieNode>;
|
|
32
|
-
//# sourceMappingURL=encode-shared.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"encode-shared.d.ts","sourceRoot":"","sources":["../../../src/internal/encode-shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,cAAc,GACpB,MAAM,GACN;IACI;;;OAGG;IACH,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,kEAAkE;IAClE,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC3C,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAER;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC3B,UAAU,EAAE,MAAM,GACnB,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAqF7B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"encode-shared.js","sourceRoot":"","sources":["../../../src/internal/encode-shared.ts"],"names":[],"mappings":"AAyBA;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC3B,UAAkB;IAElB,MAAM,GAAG,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC9C,MAAM,WAAW,GAAG,UAAU,CAAC,MAAM,CAAC;IACtC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,UAAU,GAAG,CAAC,CAAC,CAAC;IAEpB,SAAS,QAAQ;QACb,MAAM,KAAK,GAAG,MAAM,CAAC;QACrB,OAAO,MAAM,GAAG,WAAW,EAAE,CAAC;YAC1B,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,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AAU,CAAC,CAAC;oBACnC,YAAY,GAAG,QAAQ,CAAC;gBAC5B,CAAC;gBACD,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC;oBAC7B,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;gBAChD,CAAC;gBACD,MAAM,EAAE,CAAC,CAAC,WAAW;gBACrB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;YAC5C,CAAC;QACL,CAAC;aAAM,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CACX,iDAAiD,MAAM,EAAE,CAC5D,CAAC;QACN,CAAC;aAAM,CAAC;YACJ,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACxB,CAAC;QACD,UAAU,GAAG,GAAG,CAAC;IACrB,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC"}
|
package/dist/esm/package.json
DELETED
package/escape.d.ts
DELETED
package/escape.js
DELETED
package/src/decode.spec.ts
DELETED
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vitest } from "vitest";
|
|
2
|
-
import * as entities from "./decode.js";
|
|
3
|
-
|
|
4
|
-
describe("Decode test", () => {
|
|
5
|
-
const testcases = [
|
|
6
|
-
{ input: "&amp;", output: "&" },
|
|
7
|
-
{ input: "&#38;", output: "&" },
|
|
8
|
-
{ input: "&#x26;", output: "&" },
|
|
9
|
-
{ input: "&#X26;", output: "&" },
|
|
10
|
-
{ input: "&#38;", output: "&" },
|
|
11
|
-
{ input: "&#38;", output: "&" },
|
|
12
|
-
{ input: "&#38;", output: "&" },
|
|
13
|
-
{ input: ":", output: ":" },
|
|
14
|
-
{ input: ":", output: ":" },
|
|
15
|
-
{ input: ":", output: ":" },
|
|
16
|
-
{ input: ":", output: ":" },
|
|
17
|
-
{ input: "&#", output: "&#" },
|
|
18
|
-
{ input: "&>", output: "&>" },
|
|
19
|
-
{ input: "id=770&#anchor", output: "id=770&#anchor" },
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
for (const { input, output } of testcases) {
|
|
23
|
-
it(`should XML decode ${input}`, () =>
|
|
24
|
-
expect(entities.decodeXML(input)).toBe(output));
|
|
25
|
-
it(`should HTML decode ${input}`, () =>
|
|
26
|
-
expect(entities.decodeHTML(input)).toBe(output));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
it("should HTML decode partial legacy entity", () => {
|
|
30
|
-
expect(entities.decodeHTMLStrict("×bar")).toBe("×bar");
|
|
31
|
-
expect(entities.decodeHTML("×bar")).toBe("×bar");
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("should HTML decode legacy entities according to spec", () =>
|
|
35
|
-
expect(entities.decodeHTML("?&image_uri=1&ℑ=2&image=3")).toBe(
|
|
36
|
-
"?&image_uri=1&ℑ=2&image=3",
|
|
37
|
-
));
|
|
38
|
-
|
|
39
|
-
it("should back out of legacy entities", () =>
|
|
40
|
-
expect(entities.decodeHTML("&a")).toBe("&a"));
|
|
41
|
-
|
|
42
|
-
it("should not parse numeric entities in strict mode", () =>
|
|
43
|
-
expect(entities.decodeHTMLStrict("7")).toBe("7"));
|
|
44
|
-
|
|
45
|
-
it("should parse   followed by < (#852)", () =>
|
|
46
|
-
expect(entities.decodeHTML(" <")).toBe("\u00A0<"));
|
|
47
|
-
|
|
48
|
-
it("should decode trailing legacy entities", () => {
|
|
49
|
-
expect(entities.decodeHTML("⨱×bar")).toBe("⨱×bar");
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("should decode multi-byte entities", () => {
|
|
53
|
-
expect(entities.decodeHTML("≧̸")).toBe("≧̸");
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("should not decode legacy entities followed by text in attribute mode", () => {
|
|
57
|
-
expect(
|
|
58
|
-
entities.decodeHTML("¬", entities.DecodingMode.Attribute),
|
|
59
|
-
).toBe("¬");
|
|
60
|
-
|
|
61
|
-
expect(
|
|
62
|
-
entities.decodeHTML("¬i", entities.DecodingMode.Attribute),
|
|
63
|
-
).toBe("¬i");
|
|
64
|
-
|
|
65
|
-
expect(
|
|
66
|
-
entities.decodeHTML("¬=", entities.DecodingMode.Attribute),
|
|
67
|
-
).toBe("¬=");
|
|
68
|
-
|
|
69
|
-
expect(entities.decodeHTMLAttribute("¬p")).toBe("¬p");
|
|
70
|
-
expect(entities.decodeHTMLAttribute("¬P")).toBe("¬P");
|
|
71
|
-
expect(entities.decodeHTMLAttribute("¬3")).toBe("¬3");
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe("EntityDecoder", () => {
|
|
76
|
-
it("should decode decimal entities", () => {
|
|
77
|
-
const callback = vitest.fn();
|
|
78
|
-
const decoder = new entities.EntityDecoder(
|
|
79
|
-
entities.htmlDecodeTree,
|
|
80
|
-
callback,
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
expect(decoder.write("", 1)).toBe(-1);
|
|
84
|
-
expect(decoder.write("8;", 0)).toBe(5);
|
|
85
|
-
|
|
86
|
-
expect(callback).toHaveBeenCalledTimes(1);
|
|
87
|
-
expect(callback).toHaveBeenCalledWith(":".charCodeAt(0), 5);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("should decode hex entities", () => {
|
|
91
|
-
const callback = vitest.fn();
|
|
92
|
-
const decoder = new entities.EntityDecoder(
|
|
93
|
-
entities.htmlDecodeTree,
|
|
94
|
-
callback,
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
expect(decoder.write(":", 1)).toBe(6);
|
|
98
|
-
|
|
99
|
-
expect(callback).toHaveBeenCalledTimes(1);
|
|
100
|
-
expect(callback).toHaveBeenCalledWith(":".charCodeAt(0), 6);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("should decode named entities", () => {
|
|
104
|
-
const callback = vitest.fn();
|
|
105
|
-
const decoder = new entities.EntityDecoder(
|
|
106
|
-
entities.htmlDecodeTree,
|
|
107
|
-
callback,
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
expect(decoder.write("&", 1)).toBe(5);
|
|
111
|
-
|
|
112
|
-
expect(callback).toHaveBeenCalledTimes(1);
|
|
113
|
-
expect(callback).toHaveBeenCalledWith("&".charCodeAt(0), 5);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("should decode legacy entities", () => {
|
|
117
|
-
const callback = vitest.fn();
|
|
118
|
-
const decoder = new entities.EntityDecoder(
|
|
119
|
-
entities.htmlDecodeTree,
|
|
120
|
-
callback,
|
|
121
|
-
);
|
|
122
|
-
decoder.startEntity(entities.DecodingMode.Legacy);
|
|
123
|
-
|
|
124
|
-
expect(decoder.write("&", 1)).toBe(-1);
|
|
125
|
-
|
|
126
|
-
expect(callback).toHaveBeenCalledTimes(0);
|
|
127
|
-
|
|
128
|
-
expect(decoder.end()).toBe(4);
|
|
129
|
-
|
|
130
|
-
expect(callback).toHaveBeenCalledTimes(1);
|
|
131
|
-
expect(callback).toHaveBeenCalledWith("&".charCodeAt(0), 4);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it("should decode named entity written character by character", () => {
|
|
135
|
-
const callback = vitest.fn();
|
|
136
|
-
const decoder = new entities.EntityDecoder(
|
|
137
|
-
entities.htmlDecodeTree,
|
|
138
|
-
callback,
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
for (const c of "amp") {
|
|
142
|
-
expect(decoder.write(c, 0)).toBe(-1);
|
|
143
|
-
}
|
|
144
|
-
expect(decoder.write(";", 0)).toBe(5);
|
|
145
|
-
|
|
146
|
-
expect(callback).toHaveBeenCalledTimes(1);
|
|
147
|
-
expect(callback).toHaveBeenCalledWith("&".charCodeAt(0), 5);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it("should decode numeric entity written character by character", () => {
|
|
151
|
-
const callback = vitest.fn();
|
|
152
|
-
const decoder = new entities.EntityDecoder(
|
|
153
|
-
entities.htmlDecodeTree,
|
|
154
|
-
callback,
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
for (const c of "#x3a") {
|
|
158
|
-
expect(decoder.write(c, 0)).toBe(-1);
|
|
159
|
-
}
|
|
160
|
-
expect(decoder.write(";", 0)).toBe(6);
|
|
161
|
-
|
|
162
|
-
expect(callback).toHaveBeenCalledTimes(1);
|
|
163
|
-
expect(callback).toHaveBeenCalledWith(":".charCodeAt(0), 6);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it("should decode hex entities across several chunks", () => {
|
|
167
|
-
const callback = vitest.fn();
|
|
168
|
-
const decoder = new entities.EntityDecoder(
|
|
169
|
-
entities.htmlDecodeTree,
|
|
170
|
-
callback,
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
for (const chunk of ["#x", "cf", "ff", "d"]) {
|
|
174
|
-
expect(decoder.write(chunk, 0)).toBe(-1);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
expect(decoder.write(";", 0)).toBe(9);
|
|
178
|
-
expect(callback).toHaveBeenCalledTimes(1);
|
|
179
|
-
expect(callback).toHaveBeenCalledWith(0xc_ff_fd, 9);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it("should not fail if nothing is written", () => {
|
|
183
|
-
const callback = vitest.fn();
|
|
184
|
-
const decoder = new entities.EntityDecoder(
|
|
185
|
-
entities.htmlDecodeTree,
|
|
186
|
-
callback,
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
expect(decoder.end()).toBe(0);
|
|
190
|
-
expect(callback).toHaveBeenCalledTimes(0);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
/*
|
|
194
|
-
* Focused tests exercising early exit paths inside a compact run in the real trie.
|
|
195
|
-
* Discovered prefix: "zi" followed by compact run "grarr"; mismatching inside this run should
|
|
196
|
-
* return 0 with no emission (result still 0).
|
|
197
|
-
*/
|
|
198
|
-
describe("compact run mismatches", () => {
|
|
199
|
-
it("first run character mismatch returns 0", () => {
|
|
200
|
-
const callback = vitest.fn();
|
|
201
|
-
const d = new entities.EntityDecoder(
|
|
202
|
-
entities.htmlDecodeTree,
|
|
203
|
-
callback,
|
|
204
|
-
);
|
|
205
|
-
d.startEntity(entities.DecodingMode.Strict);
|
|
206
|
-
// After '&': correct prefix 'zi', wrong first run char 'X' (expected 'g').
|
|
207
|
-
expect(d.write("ziXgrar", 0)).toBe(0);
|
|
208
|
-
expect(callback).not.toHaveBeenCalled();
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it("mismatch after one correct run char returns 0", () => {
|
|
212
|
-
const callback = vitest.fn();
|
|
213
|
-
const d = new entities.EntityDecoder(
|
|
214
|
-
entities.htmlDecodeTree,
|
|
215
|
-
callback,
|
|
216
|
-
);
|
|
217
|
-
d.startEntity(entities.DecodingMode.Strict);
|
|
218
|
-
// 'zig' matches prefix + first run char; next char 'X' mismatches expected 'r'.
|
|
219
|
-
expect(d.write("zigXarr", 0)).toBe(0);
|
|
220
|
-
expect(callback).not.toHaveBeenCalled();
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it("mismatch after two correct run chars returns 0", () => {
|
|
224
|
-
const callback = vitest.fn();
|
|
225
|
-
const d = new entities.EntityDecoder(
|
|
226
|
-
entities.htmlDecodeTree,
|
|
227
|
-
callback,
|
|
228
|
-
);
|
|
229
|
-
d.startEntity(entities.DecodingMode.Strict);
|
|
230
|
-
// 'zigr' matches prefix + first two run chars; next char 'X' mismatches expected 'a'.
|
|
231
|
-
expect(d.write("zigrXrr", 0)).toBe(0);
|
|
232
|
-
expect(callback).not.toHaveBeenCalled();
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
describe("errors", () => {
|
|
237
|
-
it("should produce an error for a named entity without a semicolon", () => {
|
|
238
|
-
const errorHandlers = {
|
|
239
|
-
missingSemicolonAfterCharacterReference: vitest.fn(),
|
|
240
|
-
absenceOfDigitsInNumericCharacterReference: vitest.fn(),
|
|
241
|
-
validateNumericCharacterReference: vitest.fn(),
|
|
242
|
-
};
|
|
243
|
-
const callback = vitest.fn();
|
|
244
|
-
const decoder = new entities.EntityDecoder(
|
|
245
|
-
entities.htmlDecodeTree,
|
|
246
|
-
callback,
|
|
247
|
-
errorHandlers,
|
|
248
|
-
);
|
|
249
|
-
|
|
250
|
-
decoder.startEntity(entities.DecodingMode.Legacy);
|
|
251
|
-
expect(decoder.write("&", 1)).toBe(5);
|
|
252
|
-
expect(callback).toHaveBeenCalledTimes(1);
|
|
253
|
-
expect(callback).toHaveBeenCalledWith("&".charCodeAt(0), 5);
|
|
254
|
-
expect(
|
|
255
|
-
errorHandlers.missingSemicolonAfterCharacterReference,
|
|
256
|
-
).toHaveBeenCalledTimes(0);
|
|
257
|
-
|
|
258
|
-
decoder.startEntity(entities.DecodingMode.Legacy);
|
|
259
|
-
expect(decoder.write("&", 1)).toBe(-1);
|
|
260
|
-
expect(decoder.end()).toBe(4);
|
|
261
|
-
|
|
262
|
-
expect(callback).toHaveBeenCalledTimes(2);
|
|
263
|
-
expect(callback).toHaveBeenLastCalledWith("&".charCodeAt(0), 4);
|
|
264
|
-
expect(
|
|
265
|
-
errorHandlers.missingSemicolonAfterCharacterReference,
|
|
266
|
-
).toHaveBeenCalledTimes(1);
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it("should produce an error for a numeric entity without a semicolon", () => {
|
|
270
|
-
const errorHandlers = {
|
|
271
|
-
missingSemicolonAfterCharacterReference: vitest.fn(),
|
|
272
|
-
absenceOfDigitsInNumericCharacterReference: vitest.fn(),
|
|
273
|
-
validateNumericCharacterReference: vitest.fn(),
|
|
274
|
-
};
|
|
275
|
-
const callback = vitest.fn();
|
|
276
|
-
const decoder = new entities.EntityDecoder(
|
|
277
|
-
entities.htmlDecodeTree,
|
|
278
|
-
callback,
|
|
279
|
-
errorHandlers,
|
|
280
|
-
);
|
|
281
|
-
|
|
282
|
-
decoder.startEntity(entities.DecodingMode.Legacy);
|
|
283
|
-
expect(decoder.write(":", 1)).toBe(-1);
|
|
284
|
-
expect(decoder.end()).toBe(5);
|
|
285
|
-
|
|
286
|
-
expect(callback).toHaveBeenCalledTimes(1);
|
|
287
|
-
expect(callback).toHaveBeenCalledWith(0x3a, 5);
|
|
288
|
-
expect(
|
|
289
|
-
errorHandlers.missingSemicolonAfterCharacterReference,
|
|
290
|
-
).toHaveBeenCalledTimes(1);
|
|
291
|
-
expect(
|
|
292
|
-
errorHandlers.absenceOfDigitsInNumericCharacterReference,
|
|
293
|
-
).toHaveBeenCalledTimes(0);
|
|
294
|
-
expect(
|
|
295
|
-
errorHandlers.validateNumericCharacterReference,
|
|
296
|
-
).toHaveBeenCalledTimes(1);
|
|
297
|
-
expect(
|
|
298
|
-
errorHandlers.validateNumericCharacterReference,
|
|
299
|
-
).toHaveBeenCalledWith(0x3a);
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
it("should produce an error for numeric entities without digits", () => {
|
|
303
|
-
const errorHandlers = {
|
|
304
|
-
missingSemicolonAfterCharacterReference: vitest.fn(),
|
|
305
|
-
absenceOfDigitsInNumericCharacterReference: vitest.fn(),
|
|
306
|
-
validateNumericCharacterReference: vitest.fn(),
|
|
307
|
-
};
|
|
308
|
-
const callback = vitest.fn();
|
|
309
|
-
const decoder = new entities.EntityDecoder(
|
|
310
|
-
entities.htmlDecodeTree,
|
|
311
|
-
callback,
|
|
312
|
-
errorHandlers,
|
|
313
|
-
);
|
|
314
|
-
|
|
315
|
-
decoder.startEntity(entities.DecodingMode.Legacy);
|
|
316
|
-
expect(decoder.write("&#", 1)).toBe(-1);
|
|
317
|
-
expect(decoder.end()).toBe(0);
|
|
318
|
-
|
|
319
|
-
expect(callback).toHaveBeenCalledTimes(0);
|
|
320
|
-
expect(
|
|
321
|
-
errorHandlers.missingSemicolonAfterCharacterReference,
|
|
322
|
-
).toHaveBeenCalledTimes(0);
|
|
323
|
-
expect(
|
|
324
|
-
errorHandlers.absenceOfDigitsInNumericCharacterReference,
|
|
325
|
-
).toHaveBeenCalledTimes(1);
|
|
326
|
-
expect(
|
|
327
|
-
errorHandlers.absenceOfDigitsInNumericCharacterReference,
|
|
328
|
-
).toHaveBeenCalledWith(2);
|
|
329
|
-
expect(
|
|
330
|
-
errorHandlers.validateNumericCharacterReference,
|
|
331
|
-
).toHaveBeenCalledTimes(0);
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
it("should produce an error for hex entities without digits", () => {
|
|
335
|
-
const errorHandlers = {
|
|
336
|
-
missingSemicolonAfterCharacterReference: vitest.fn(),
|
|
337
|
-
absenceOfDigitsInNumericCharacterReference: vitest.fn(),
|
|
338
|
-
validateNumericCharacterReference: vitest.fn(),
|
|
339
|
-
};
|
|
340
|
-
const callback = vitest.fn();
|
|
341
|
-
const decoder = new entities.EntityDecoder(
|
|
342
|
-
entities.htmlDecodeTree,
|
|
343
|
-
callback,
|
|
344
|
-
errorHandlers,
|
|
345
|
-
);
|
|
346
|
-
|
|
347
|
-
decoder.startEntity(entities.DecodingMode.Legacy);
|
|
348
|
-
expect(decoder.write("&#x", 1)).toBe(-1);
|
|
349
|
-
expect(decoder.end()).toBe(0);
|
|
350
|
-
|
|
351
|
-
expect(callback).toHaveBeenCalledTimes(0);
|
|
352
|
-
expect(
|
|
353
|
-
errorHandlers.missingSemicolonAfterCharacterReference,
|
|
354
|
-
).toHaveBeenCalledTimes(0);
|
|
355
|
-
expect(
|
|
356
|
-
errorHandlers.absenceOfDigitsInNumericCharacterReference,
|
|
357
|
-
).toHaveBeenCalledTimes(1);
|
|
358
|
-
expect(
|
|
359
|
-
errorHandlers.validateNumericCharacterReference,
|
|
360
|
-
).toHaveBeenCalledTimes(0);
|
|
361
|
-
});
|
|
362
|
-
});
|
|
363
|
-
});
|