codebuff 1.0.325 → 1.0.326
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/checkpoints/file-manager.js +21 -21
- package/dist/checkpoints/file-manager.js.map +1 -1
- package/dist/common/actions.d.ts +58 -58
- package/dist/common/analytics.d.ts +1 -1
- package/dist/common/browser-actions.d.ts +277 -277
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.d.ts.map +1 -1
- package/dist/common/constants.js +9 -0
- package/dist/common/constants.js.map +1 -1
- package/dist/common/db/schema.d.ts +5 -0
- package/dist/common/db/schema.d.ts.map +1 -1
- package/dist/common/db/schema.js.map +1 -1
- package/dist/common/types/message.d.ts +16 -16
- package/dist/common/websockets/websocket-schema.d.ts +122 -122
- package/dist/index.js +5 -5
- package/dist/project-files.d.ts +1 -0
- package/dist/project-files.js +24 -4
- package/dist/project-files.js.map +1 -1
- package/dist/workers/project-context.js +5 -1
- package/dist/workers/project-context.js.map +1 -1
- package/package.json +16 -16
- package/dist/code-map/test-langs/test.d.ts +0 -12
- package/dist/code-map/test-langs/test.d.ts.map +0 -1
- package/dist/code-map/test-langs/test.js +0 -23
- package/dist/code-map/test-langs/test.js.map +0 -1
- package/dist/common/db/env.d.mts +0 -4
- package/dist/common/db/env.mjs +0 -26
- package/dist/common/db/env.mjs.map +0 -1
- package/dist/common/env.d.mts +0 -13
- package/dist/common/env.mjs +0 -43
- package/dist/common/env.mjs.map +0 -1
- package/dist/common/src/actions.d.ts +0 -2673
- package/dist/common/src/actions.d.ts.map +0 -1
- package/dist/common/src/actions.js +0 -167
- package/dist/common/src/actions.js.map +0 -1
- package/dist/common/src/analytics.d.ts +0 -6
- package/dist/common/src/analytics.d.ts.map +0 -1
- package/dist/common/src/analytics.js +0 -60
- package/dist/common/src/analytics.js.map +0 -1
- package/dist/common/src/api-keys/constants.d.ts +0 -9
- package/dist/common/src/api-keys/constants.d.ts.map +0 -1
- package/dist/common/src/api-keys/constants.js +0 -26
- package/dist/common/src/api-keys/constants.js.map +0 -1
- package/dist/common/src/api-keys/crypto.d.ts +0 -25
- package/dist/common/src/api-keys/crypto.d.ts.map +0 -1
- package/dist/common/src/api-keys/crypto.js +0 -186
- package/dist/common/src/api-keys/crypto.js.map +0 -1
- package/dist/common/src/browser-actions.d.ts +0 -4416
- package/dist/common/src/browser-actions.d.ts.map +0 -1
- package/dist/common/src/browser-actions.js +0 -343
- package/dist/common/src/browser-actions.js.map +0 -1
- package/dist/common/src/constants/analytics-events.d.ts +0 -28
- package/dist/common/src/constants/analytics-events.d.ts.map +0 -1
- package/dist/common/src/constants/analytics-events.js +0 -36
- package/dist/common/src/constants/analytics-events.js.map +0 -1
- package/dist/common/src/constants/grant-priorities.d.ts +0 -3
- package/dist/common/src/constants/grant-priorities.d.ts.map +0 -1
- package/dist/common/src/constants/grant-priorities.js +0 -11
- package/dist/common/src/constants/grant-priorities.js.map +0 -1
- package/dist/common/src/constants/tools.d.ts +0 -20
- package/dist/common/src/constants/tools.d.ts.map +0 -1
- package/dist/common/src/constants/tools.js +0 -47
- package/dist/common/src/constants/tools.js.map +0 -1
- package/dist/common/src/constants.d.ts +0 -152
- package/dist/common/src/constants.d.ts.map +0 -1
- package/dist/common/src/constants.js +0 -222
- package/dist/common/src/constants.js.map +0 -1
- package/dist/common/src/db/drizzle.config.d.ts +0 -3
- package/dist/common/src/db/drizzle.config.d.ts.map +0 -1
- package/dist/common/src/db/drizzle.config.js +0 -17
- package/dist/common/src/db/drizzle.config.js.map +0 -1
- package/dist/common/src/db/index.d.ts +0 -7
- package/dist/common/src/db/index.d.ts.map +0 -1
- package/dist/common/src/db/index.js +0 -35
- package/dist/common/src/db/index.js.map +0 -1
- package/dist/common/src/db/schema.d.ts +0 -2289
- package/dist/common/src/db/schema.d.ts.map +0 -1
- package/dist/common/src/db/schema.js +0 -296
- package/dist/common/src/db/schema.js.map +0 -1
- package/dist/common/src/db/transaction.d.ts +0 -13
- package/dist/common/src/db/transaction.d.ts.map +0 -1
- package/dist/common/src/db/transaction.js +0 -36
- package/dist/common/src/db/transaction.js.map +0 -1
- package/dist/common/src/json-config/__tests__/constants.test.d.ts +0 -2
- package/dist/common/src/json-config/__tests__/constants.test.d.ts.map +0 -1
- package/dist/common/src/json-config/__tests__/constants.test.js +0 -273
- package/dist/common/src/json-config/__tests__/constants.test.js.map +0 -1
- package/dist/common/src/json-config/__tests__/stringify-schema.test.d.ts +0 -2
- package/dist/common/src/json-config/__tests__/stringify-schema.test.d.ts.map +0 -1
- package/dist/common/src/json-config/__tests__/stringify-schema.test.js +0 -66
- package/dist/common/src/json-config/__tests__/stringify-schema.test.js.map +0 -1
- package/dist/common/src/json-config/constants.d.ts +0 -138
- package/dist/common/src/json-config/constants.d.ts.map +0 -1
- package/dist/common/src/json-config/constants.js +0 -78
- package/dist/common/src/json-config/constants.js.map +0 -1
- package/dist/common/src/json-config/stringify-schema.d.ts +0 -10
- package/dist/common/src/json-config/stringify-schema.d.ts.map +0 -1
- package/dist/common/src/json-config/stringify-schema.js +0 -131
- package/dist/common/src/json-config/stringify-schema.js.map +0 -1
- package/dist/common/src/project-file-tree.d.ts +0 -12
- package/dist/common/src/project-file-tree.d.ts.map +0 -1
- package/dist/common/src/project-file-tree.js +0 -212
- package/dist/common/src/project-file-tree.js.map +0 -1
- package/dist/common/src/types/agent-state.d.ts +0 -227
- package/dist/common/src/types/agent-state.d.ts.map +0 -1
- package/dist/common/src/types/agent-state.js +0 -34
- package/dist/common/src/types/agent-state.js.map +0 -1
- package/dist/common/src/types/grant.d.ts +0 -3
- package/dist/common/src/types/grant.d.ts.map +0 -1
- package/dist/common/src/types/grant.js +0 -11
- package/dist/common/src/types/grant.js.map +0 -1
- package/dist/common/src/types/message.d.ts +0 -320
- package/dist/common/src/types/message.d.ts.map +0 -1
- package/dist/common/src/types/message.js +0 -60
- package/dist/common/src/types/message.js.map +0 -1
- package/dist/common/src/types/organization.d.ts +0 -106
- package/dist/common/src/types/organization.d.ts.map +0 -1
- package/dist/common/src/types/organization.js +0 -3
- package/dist/common/src/types/organization.js.map +0 -1
- package/dist/common/src/types/referral.d.ts +0 -3
- package/dist/common/src/types/referral.d.ts.map +0 -1
- package/dist/common/src/types/referral.js +0 -5
- package/dist/common/src/types/referral.js.map +0 -1
- package/dist/common/src/types/tools.d.ts +0 -6
- package/dist/common/src/types/tools.d.ts.map +0 -1
- package/dist/common/src/types/tools.js +0 -3
- package/dist/common/src/types/tools.js.map +0 -1
- package/dist/common/src/types/usage.d.ts +0 -41
- package/dist/common/src/types/usage.d.ts.map +0 -1
- package/dist/common/src/types/usage.js +0 -16
- package/dist/common/src/types/usage.js.map +0 -1
- package/dist/common/src/util/__tests__/messages.test.d.ts +0 -2
- package/dist/common/src/util/__tests__/messages.test.d.ts.map +0 -1
- package/dist/common/src/util/__tests__/messages.test.js +0 -70
- package/dist/common/src/util/__tests__/messages.test.js.map +0 -1
- package/dist/common/src/util/__tests__/saxy.test.d.ts +0 -2
- package/dist/common/src/util/__tests__/saxy.test.d.ts.map +0 -1
- package/dist/common/src/util/__tests__/saxy.test.js +0 -906
- package/dist/common/src/util/__tests__/saxy.test.js.map +0 -1
- package/dist/common/src/util/__tests__/string.test.d.ts +0 -2
- package/dist/common/src/util/__tests__/string.test.d.ts.map +0 -1
- package/dist/common/src/util/__tests__/string.test.js +0 -82
- package/dist/common/src/util/__tests__/string.test.js.map +0 -1
- package/dist/common/src/util/array.d.ts +0 -7
- package/dist/common/src/util/array.d.ts.map +0 -1
- package/dist/common/src/util/array.js +0 -32
- package/dist/common/src/util/array.js.map +0 -1
- package/dist/common/src/util/changes.d.ts +0 -9
- package/dist/common/src/util/changes.d.ts.map +0 -1
- package/dist/common/src/util/changes.js +0 -87
- package/dist/common/src/util/changes.js.map +0 -1
- package/dist/common/src/util/credentials.d.ts +0 -26
- package/dist/common/src/util/credentials.d.ts.map +0 -1
- package/dist/common/src/util/credentials.js +0 -24
- package/dist/common/src/util/credentials.js.map +0 -1
- package/dist/common/src/util/currency.d.ts +0 -15
- package/dist/common/src/util/currency.d.ts.map +0 -1
- package/dist/common/src/util/currency.js +0 -23
- package/dist/common/src/util/currency.js.map +0 -1
- package/dist/common/src/util/dates.d.ts +0 -11
- package/dist/common/src/util/dates.d.ts.map +0 -1
- package/dist/common/src/util/dates.js +0 -22
- package/dist/common/src/util/dates.js.map +0 -1
- package/dist/common/src/util/file.d.ts +0 -163
- package/dist/common/src/util/file.d.ts.map +0 -1
- package/dist/common/src/util/file.js +0 -192
- package/dist/common/src/util/file.js.map +0 -1
- package/dist/common/src/util/git.d.ts +0 -7
- package/dist/common/src/util/git.d.ts.map +0 -1
- package/dist/common/src/util/git.js +0 -81
- package/dist/common/src/util/git.js.map +0 -1
- package/dist/common/src/util/logger.d.ts +0 -9
- package/dist/common/src/util/logger.d.ts.map +0 -1
- package/dist/common/src/util/logger.js +0 -52
- package/dist/common/src/util/logger.js.map +0 -1
- package/dist/common/src/util/lru-cache.d.ts +0 -31
- package/dist/common/src/util/lru-cache.d.ts.map +0 -1
- package/dist/common/src/util/lru-cache.js +0 -68
- package/dist/common/src/util/lru-cache.js.map +0 -1
- package/dist/common/src/util/messages.d.ts +0 -12
- package/dist/common/src/util/messages.d.ts.map +0 -1
- package/dist/common/src/util/messages.js +0 -81
- package/dist/common/src/util/messages.js.map +0 -1
- package/dist/common/src/util/min-heap.d.ts +0 -16
- package/dist/common/src/util/min-heap.d.ts.map +0 -1
- package/dist/common/src/util/min-heap.js +0 -73
- package/dist/common/src/util/min-heap.js.map +0 -1
- package/dist/common/src/util/object.d.ts +0 -19
- package/dist/common/src/util/object.d.ts.map +0 -1
- package/dist/common/src/util/object.js +0 -91
- package/dist/common/src/util/object.js.map +0 -1
- package/dist/common/src/util/patch.d.ts +0 -2
- package/dist/common/src/util/patch.d.ts.map +0 -1
- package/dist/common/src/util/patch.js +0 -215
- package/dist/common/src/util/patch.js.map +0 -1
- package/dist/common/src/util/promise.d.ts +0 -17
- package/dist/common/src/util/promise.d.ts.map +0 -1
- package/dist/common/src/util/promise.js +0 -51
- package/dist/common/src/util/promise.js.map +0 -1
- package/dist/common/src/util/random.d.ts +0 -2
- package/dist/common/src/util/random.d.ts.map +0 -1
- package/dist/common/src/util/random.js +0 -17
- package/dist/common/src/util/random.js.map +0 -1
- package/dist/common/src/util/referral.d.ts +0 -2
- package/dist/common/src/util/referral.d.ts.map +0 -1
- package/dist/common/src/util/referral.js +0 -6
- package/dist/common/src/util/referral.js.map +0 -1
- package/dist/common/src/util/saxy.d.ts +0 -179
- package/dist/common/src/util/saxy.d.ts.map +0 -1
- package/dist/common/src/util/saxy.js +0 -548
- package/dist/common/src/util/saxy.js.map +0 -1
- package/dist/common/src/util/string.d.ts +0 -80
- package/dist/common/src/util/string.d.ts.map +0 -1
- package/dist/common/src/util/string.js +0 -264
- package/dist/common/src/util/string.js.map +0 -1
- package/dist/common/src/util/stripe.d.ts +0 -4
- package/dist/common/src/util/stripe.d.ts.map +0 -1
- package/dist/common/src/util/stripe.js +0 -22
- package/dist/common/src/util/stripe.js.map +0 -1
- package/dist/common/src/util/sync-failure.d.ts +0 -2
- package/dist/common/src/util/sync-failure.d.ts.map +0 -1
- package/dist/common/src/util/sync-failure.js +0 -57
- package/dist/common/src/util/sync-failure.js.map +0 -1
- package/dist/common/src/websockets/websocket-client.d.ts +0 -43
- package/dist/common/src/websockets/websocket-client.d.ts.map +0 -1
- package/dist/common/src/websockets/websocket-client.js +0 -216
- package/dist/common/src/websockets/websocket-client.js.map +0 -1
- package/dist/common/src/websockets/websocket-schema.d.ts +0 -5159
- package/dist/common/src/websockets/websocket-schema.d.ts.map +0 -1
- package/dist/common/src/websockets/websocket-schema.js +0 -55
- package/dist/common/src/websockets/websocket-schema.js.map +0 -1
- package/dist/common/tsconfig.tsbuildinfo +0 -1
|
@@ -1,906 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const bun_test_1 = require("bun:test");
|
|
4
|
-
const saxy_1 = require("../saxy");
|
|
5
|
-
(0, bun_test_1.describe)('Saxy XML Parser', () => {
|
|
6
|
-
// Helper function to process XML and get events
|
|
7
|
-
const processXML = (xml, schema, shouldParseEntities = true) => {
|
|
8
|
-
const events = [];
|
|
9
|
-
const parser = new saxy_1.Saxy(schema, shouldParseEntities);
|
|
10
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
11
|
-
parser.on('tagopen', (data) => events.push({ type: 'tagopen', data }));
|
|
12
|
-
parser.on('tagclose', (data) => events.push({ type: 'tagclose', data }));
|
|
13
|
-
parser.write(xml);
|
|
14
|
-
parser.end();
|
|
15
|
-
return events;
|
|
16
|
-
};
|
|
17
|
-
(0, bun_test_1.describe)('Schema Validation with Text Conversion', () => {
|
|
18
|
-
(0, bun_test_1.it)('should convert invalid top-level tags to text nodes', () => {
|
|
19
|
-
const schema = { root: ['child'] };
|
|
20
|
-
const xml = '<invalid>content</invalid>';
|
|
21
|
-
const events = processXML(xml, schema);
|
|
22
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
23
|
-
{
|
|
24
|
-
type: 'text',
|
|
25
|
-
data: { contents: '<invalid>' },
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
type: 'text',
|
|
29
|
-
data: { contents: 'content' },
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
type: 'text',
|
|
33
|
-
data: { contents: '</invalid>' },
|
|
34
|
-
},
|
|
35
|
-
]);
|
|
36
|
-
});
|
|
37
|
-
(0, bun_test_1.it)('should convert invalid nested tags to text nodes', () => {
|
|
38
|
-
const schema = { root: ['child'] };
|
|
39
|
-
const xml = '<other><invalid>content</invalid></other>';
|
|
40
|
-
const events = processXML(xml, schema);
|
|
41
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
42
|
-
{
|
|
43
|
-
type: 'text',
|
|
44
|
-
data: { contents: '<other>' },
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
type: 'text',
|
|
48
|
-
data: { contents: '<invalid>' },
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
type: 'text',
|
|
52
|
-
data: { contents: 'content' },
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
type: 'text',
|
|
56
|
-
data: { contents: '</invalid>' },
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
type: 'text',
|
|
60
|
-
data: { contents: '</other>' },
|
|
61
|
-
},
|
|
62
|
-
]);
|
|
63
|
-
});
|
|
64
|
-
(0, bun_test_1.it)('should handle valid nested tags according to schema', () => {
|
|
65
|
-
const schema = { root: ['child'] };
|
|
66
|
-
const xml = '<root><child>content</child></root>';
|
|
67
|
-
const events = processXML(xml, schema);
|
|
68
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
69
|
-
{
|
|
70
|
-
data: {
|
|
71
|
-
attrs: '',
|
|
72
|
-
isSelfClosing: false,
|
|
73
|
-
name: 'root',
|
|
74
|
-
rawTag: '<root>',
|
|
75
|
-
},
|
|
76
|
-
type: 'tagopen',
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
data: {
|
|
80
|
-
attrs: '',
|
|
81
|
-
isSelfClosing: false,
|
|
82
|
-
name: 'child',
|
|
83
|
-
rawTag: '<child>',
|
|
84
|
-
},
|
|
85
|
-
type: 'tagopen',
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
data: {
|
|
89
|
-
contents: 'content',
|
|
90
|
-
},
|
|
91
|
-
type: 'text',
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
data: {
|
|
95
|
-
name: 'child',
|
|
96
|
-
rawTag: '</child>',
|
|
97
|
-
},
|
|
98
|
-
type: 'tagclose',
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
data: {
|
|
102
|
-
name: 'root',
|
|
103
|
-
rawTag: '</root>',
|
|
104
|
-
},
|
|
105
|
-
type: 'tagclose',
|
|
106
|
-
},
|
|
107
|
-
]);
|
|
108
|
-
});
|
|
109
|
-
(0, bun_test_1.it)('should convert closing tags to text when parent is invalid', () => {
|
|
110
|
-
const schema = { root: ['child'] };
|
|
111
|
-
const xml = '<root><invalid>content</invalid><child/></root>';
|
|
112
|
-
const events = processXML(xml, schema);
|
|
113
|
-
(0, bun_test_1.expect)(events[1]).toEqual({
|
|
114
|
-
type: 'text',
|
|
115
|
-
data: { contents: '<invalid>' },
|
|
116
|
-
});
|
|
117
|
-
(0, bun_test_1.expect)(events[2]).toEqual({
|
|
118
|
-
type: 'text',
|
|
119
|
-
data: { contents: 'content' },
|
|
120
|
-
});
|
|
121
|
-
(0, bun_test_1.expect)(events[3]).toEqual({
|
|
122
|
-
type: 'text',
|
|
123
|
-
data: { contents: '</invalid>' },
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
(0, bun_test_1.it)('should handle tags starting with whitespace as text', () => {
|
|
127
|
-
const schema = { root: ['child'] };
|
|
128
|
-
const xml = '<root>< invalid>content</invalid></root>';
|
|
129
|
-
const events = processXML(xml, schema);
|
|
130
|
-
(0, bun_test_1.expect)(events[1]).toEqual({
|
|
131
|
-
type: 'text',
|
|
132
|
-
data: { contents: '< invalid>content' },
|
|
133
|
-
});
|
|
134
|
-
(0, bun_test_1.expect)(events[2]).toEqual({
|
|
135
|
-
type: 'text',
|
|
136
|
-
data: { contents: '</invalid>' },
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
(0, bun_test_1.describe)('Edge Cases', () => {
|
|
141
|
-
(0, bun_test_1.it)('should handle self-closing invalid tags', () => {
|
|
142
|
-
const schema = { root: ['child'] };
|
|
143
|
-
const xml = '<root><invalid/></root>';
|
|
144
|
-
const events = processXML(xml, schema);
|
|
145
|
-
(0, bun_test_1.expect)(events[1]).toEqual({
|
|
146
|
-
type: 'text',
|
|
147
|
-
data: { contents: '<invalid/>' },
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
(0, bun_test_1.it)('should handle nested invalid tags', () => {
|
|
151
|
-
const schema = { root: ['child'] };
|
|
152
|
-
const xml = '<root><invalid><alsoinvalid/></invalid></root>';
|
|
153
|
-
const events = processXML(xml, schema);
|
|
154
|
-
(0, bun_test_1.expect)(events[1]).toEqual({
|
|
155
|
-
type: 'text',
|
|
156
|
-
data: { contents: '<invalid>' },
|
|
157
|
-
});
|
|
158
|
-
(0, bun_test_1.expect)(events[2]).toEqual({
|
|
159
|
-
type: 'text',
|
|
160
|
-
data: { contents: '<alsoinvalid/>' },
|
|
161
|
-
});
|
|
162
|
-
(0, bun_test_1.expect)(events[3]).toEqual({
|
|
163
|
-
type: 'text',
|
|
164
|
-
data: { contents: '</invalid>' },
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
(0, bun_test_1.it)('should preserve attributes in converted text nodes', () => {
|
|
168
|
-
const schema = { root: ['child'] };
|
|
169
|
-
const xml = '<root><invalid attr="value">content</invalid></root>';
|
|
170
|
-
const events = processXML(xml, schema);
|
|
171
|
-
(0, bun_test_1.expect)(events[1]).toEqual({
|
|
172
|
-
type: 'text',
|
|
173
|
-
data: { contents: '<invalid attr="value">' },
|
|
174
|
-
});
|
|
175
|
-
(0, bun_test_1.expect)(events[2]).toEqual({
|
|
176
|
-
type: 'text',
|
|
177
|
-
data: { contents: 'content' },
|
|
178
|
-
});
|
|
179
|
-
(0, bun_test_1.expect)(events[3]).toEqual({
|
|
180
|
-
type: 'text',
|
|
181
|
-
data: { contents: '</invalid>' },
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
(0, bun_test_1.it)('should handle text that looks like invalid XML tags', () => {
|
|
186
|
-
const parser = new saxy_1.Saxy();
|
|
187
|
-
const events = [];
|
|
188
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
189
|
-
parser.on('tagopen', (data) => events.push({ type: 'tagopen', data }));
|
|
190
|
-
parser.on('tagclose', (data) => events.push({ type: 'tagclose', data }));
|
|
191
|
-
parser.write('This is < not a tag> and < another not a tag> but <valid>this is</valid>');
|
|
192
|
-
parser.end();
|
|
193
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
194
|
-
{
|
|
195
|
-
data: {
|
|
196
|
-
contents: 'This is < not a tag> and < another not a tag> but ',
|
|
197
|
-
},
|
|
198
|
-
type: 'text',
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
data: {
|
|
202
|
-
attrs: '',
|
|
203
|
-
isSelfClosing: false,
|
|
204
|
-
name: 'valid',
|
|
205
|
-
rawTag: '<valid>',
|
|
206
|
-
},
|
|
207
|
-
type: 'tagopen',
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
data: {
|
|
211
|
-
contents: 'this is',
|
|
212
|
-
},
|
|
213
|
-
type: 'text',
|
|
214
|
-
},
|
|
215
|
-
{ data: { name: 'valid', rawTag: '</valid>' }, type: 'tagclose' },
|
|
216
|
-
]);
|
|
217
|
-
});
|
|
218
|
-
(0, bun_test_1.it)('should handle text with angle brackets but no valid tag names', () => {
|
|
219
|
-
const parser = new saxy_1.Saxy();
|
|
220
|
-
const events = [];
|
|
221
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
222
|
-
parser.write('Math expressions: 2 < 3 and 5 > 4');
|
|
223
|
-
parser.end();
|
|
224
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
225
|
-
{
|
|
226
|
-
type: 'text',
|
|
227
|
-
data: { contents: 'Math expressions: 2 < 3 and 5 > 4' },
|
|
228
|
-
},
|
|
229
|
-
]);
|
|
230
|
-
});
|
|
231
|
-
(0, bun_test_1.it)('should correctly parse mixed valid and invalid XML-like content', () => {
|
|
232
|
-
const parser = new saxy_1.Saxy();
|
|
233
|
-
const events = [];
|
|
234
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
235
|
-
parser.on('tagopen', (data) => events.push({ type: 'tagopen', data }));
|
|
236
|
-
parser.on('tagclose', (data) => events.push({ type: 'tagclose', data }));
|
|
237
|
-
parser.write('Text with < brackets> and <valid-tag>real XML</valid-tag> mixed together');
|
|
238
|
-
parser.end();
|
|
239
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
240
|
-
{
|
|
241
|
-
data: {
|
|
242
|
-
contents: 'Text with < brackets> and ',
|
|
243
|
-
},
|
|
244
|
-
type: 'text',
|
|
245
|
-
},
|
|
246
|
-
{
|
|
247
|
-
data: {
|
|
248
|
-
attrs: '',
|
|
249
|
-
isSelfClosing: false,
|
|
250
|
-
name: 'valid-tag',
|
|
251
|
-
rawTag: '<valid-tag>',
|
|
252
|
-
},
|
|
253
|
-
type: 'tagopen',
|
|
254
|
-
},
|
|
255
|
-
{
|
|
256
|
-
data: {
|
|
257
|
-
contents: 'real XML',
|
|
258
|
-
},
|
|
259
|
-
type: 'text',
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
data: {
|
|
263
|
-
name: 'valid-tag',
|
|
264
|
-
rawTag: '</valid-tag>',
|
|
265
|
-
},
|
|
266
|
-
type: 'tagclose',
|
|
267
|
-
},
|
|
268
|
-
{
|
|
269
|
-
data: {
|
|
270
|
-
contents: ' mixed together',
|
|
271
|
-
},
|
|
272
|
-
type: 'text',
|
|
273
|
-
},
|
|
274
|
-
]);
|
|
275
|
-
});
|
|
276
|
-
(0, bun_test_1.it)('should handle edge cases with special characters after <', () => {
|
|
277
|
-
const parser = new saxy_1.Saxy();
|
|
278
|
-
const events = [];
|
|
279
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
280
|
-
parser.write('Text with <1>, <@invalid>, and <!not-a-tag>');
|
|
281
|
-
parser.end();
|
|
282
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
283
|
-
{
|
|
284
|
-
type: 'text',
|
|
285
|
-
data: { contents: 'Text with <1>, <@invalid>, and <!not-a-tag>' },
|
|
286
|
-
},
|
|
287
|
-
]);
|
|
288
|
-
});
|
|
289
|
-
(0, bun_test_1.describe)('Text Node Handling', () => {
|
|
290
|
-
(0, bun_test_1.it)('should preserve whitespace in text nodes', () => {
|
|
291
|
-
const parser = new saxy_1.Saxy();
|
|
292
|
-
const events = [];
|
|
293
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
294
|
-
parser.write(' Text with leading and trailing spaces ');
|
|
295
|
-
parser.end();
|
|
296
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
297
|
-
{
|
|
298
|
-
type: 'text',
|
|
299
|
-
data: { contents: ' Text with leading and trailing spaces ' },
|
|
300
|
-
},
|
|
301
|
-
]);
|
|
302
|
-
});
|
|
303
|
-
(0, bun_test_1.it)('should handle HTML entities in text content', () => {
|
|
304
|
-
const parser = new saxy_1.Saxy();
|
|
305
|
-
const events = [];
|
|
306
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
307
|
-
parser.write('Text with & and < entities');
|
|
308
|
-
parser.end();
|
|
309
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
310
|
-
{
|
|
311
|
-
type: 'text',
|
|
312
|
-
data: { contents: 'Text with & and < entities' },
|
|
313
|
-
},
|
|
314
|
-
]);
|
|
315
|
-
});
|
|
316
|
-
(0, bun_test_1.it)('should handle split XML entities in text content', () => {
|
|
317
|
-
// Re-initialize parser and events array inside the test
|
|
318
|
-
const parser = new saxy_1.Saxy();
|
|
319
|
-
const events = [];
|
|
320
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
321
|
-
parser.write('Text with &am');
|
|
322
|
-
parser.write('p; and');
|
|
323
|
-
parser.write(' &l');
|
|
324
|
-
parser.write('t; entities &g');
|
|
325
|
-
parser.end();
|
|
326
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
327
|
-
{
|
|
328
|
-
data: {
|
|
329
|
-
contents: 'Text with ',
|
|
330
|
-
},
|
|
331
|
-
type: 'text',
|
|
332
|
-
},
|
|
333
|
-
{
|
|
334
|
-
data: {
|
|
335
|
-
contents: '& and',
|
|
336
|
-
},
|
|
337
|
-
type: 'text',
|
|
338
|
-
},
|
|
339
|
-
{
|
|
340
|
-
data: {
|
|
341
|
-
contents: ' ',
|
|
342
|
-
},
|
|
343
|
-
type: 'text',
|
|
344
|
-
},
|
|
345
|
-
{
|
|
346
|
-
data: {
|
|
347
|
-
contents: '< entities ',
|
|
348
|
-
},
|
|
349
|
-
type: 'text',
|
|
350
|
-
},
|
|
351
|
-
{
|
|
352
|
-
data: {
|
|
353
|
-
contents: '&g',
|
|
354
|
-
},
|
|
355
|
-
type: 'text',
|
|
356
|
-
},
|
|
357
|
-
]);
|
|
358
|
-
(0, bun_test_1.expect)(events.map((chunk) => chunk.data.contents).join('')).toEqual('Text with & and < entities &g');
|
|
359
|
-
});
|
|
360
|
-
(0, bun_test_1.it)('should preserve whitespace between tags', () => {
|
|
361
|
-
const parser = new saxy_1.Saxy();
|
|
362
|
-
const events = [];
|
|
363
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
364
|
-
parser.on('tagopen', (data) => events.push({ type: 'tagopen', data }));
|
|
365
|
-
parser.on('tagclose', (data) => events.push({ type: 'tagclose', data }));
|
|
366
|
-
parser.write('<root> text <child> text </child> text </root>');
|
|
367
|
-
parser.end();
|
|
368
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
369
|
-
{
|
|
370
|
-
data: {
|
|
371
|
-
attrs: '',
|
|
372
|
-
isSelfClosing: false,
|
|
373
|
-
name: 'root',
|
|
374
|
-
rawTag: '<root>',
|
|
375
|
-
},
|
|
376
|
-
type: 'tagopen',
|
|
377
|
-
},
|
|
378
|
-
{
|
|
379
|
-
data: {
|
|
380
|
-
contents: ' text ',
|
|
381
|
-
},
|
|
382
|
-
type: 'text',
|
|
383
|
-
},
|
|
384
|
-
{
|
|
385
|
-
data: {
|
|
386
|
-
attrs: '',
|
|
387
|
-
isSelfClosing: false,
|
|
388
|
-
name: 'child',
|
|
389
|
-
rawTag: '<child>',
|
|
390
|
-
},
|
|
391
|
-
type: 'tagopen',
|
|
392
|
-
},
|
|
393
|
-
{
|
|
394
|
-
data: {
|
|
395
|
-
contents: ' text ',
|
|
396
|
-
},
|
|
397
|
-
type: 'text',
|
|
398
|
-
},
|
|
399
|
-
{
|
|
400
|
-
data: {
|
|
401
|
-
name: 'child',
|
|
402
|
-
rawTag: '</child>',
|
|
403
|
-
},
|
|
404
|
-
type: 'tagclose',
|
|
405
|
-
},
|
|
406
|
-
{
|
|
407
|
-
data: {
|
|
408
|
-
contents: ' text ',
|
|
409
|
-
},
|
|
410
|
-
type: 'text',
|
|
411
|
-
},
|
|
412
|
-
{
|
|
413
|
-
data: {
|
|
414
|
-
name: 'root',
|
|
415
|
-
rawTag: '</root>',
|
|
416
|
-
},
|
|
417
|
-
type: 'tagclose',
|
|
418
|
-
},
|
|
419
|
-
]);
|
|
420
|
-
});
|
|
421
|
-
(0, bun_test_1.it)('should handle multiple HTML entities in the same text node', () => {
|
|
422
|
-
const parser = new saxy_1.Saxy();
|
|
423
|
-
const events = [];
|
|
424
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
425
|
-
parser.write('Text with & < > " entities');
|
|
426
|
-
parser.end();
|
|
427
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
428
|
-
{
|
|
429
|
-
type: 'text',
|
|
430
|
-
data: { contents: 'Text with & < > " entities' },
|
|
431
|
-
},
|
|
432
|
-
]);
|
|
433
|
-
});
|
|
434
|
-
(0, bun_test_1.it)('should preserve newlines in text content', () => {
|
|
435
|
-
const parser = new saxy_1.Saxy();
|
|
436
|
-
const events = [];
|
|
437
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
438
|
-
parser.write('Line 1\nLine 2\r\nLine 3');
|
|
439
|
-
parser.end();
|
|
440
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
441
|
-
{
|
|
442
|
-
type: 'text',
|
|
443
|
-
data: { contents: 'Line 1\nLine 2\r\nLine 3' },
|
|
444
|
-
},
|
|
445
|
-
]);
|
|
446
|
-
});
|
|
447
|
-
(0, bun_test_1.it)('should handle split XML entities across chunks', async () => {
|
|
448
|
-
const parser = new saxy_1.Saxy();
|
|
449
|
-
const events = [];
|
|
450
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
451
|
-
parser.on('tagopen', (data) => events.push({ type: 'tagopen', data }));
|
|
452
|
-
parser.on('tagclose', (data) => events.push({ type: 'tagclose', data }));
|
|
453
|
-
// Write the XML in chunks that split the & entity
|
|
454
|
-
parser.write('<tag>before &a');
|
|
455
|
-
parser.write('mp; after</tag>');
|
|
456
|
-
parser.end();
|
|
457
|
-
// The entity should be properly decoded and the text events should
|
|
458
|
-
// reconstruct the original text correctly
|
|
459
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
460
|
-
{
|
|
461
|
-
data: {
|
|
462
|
-
attrs: '',
|
|
463
|
-
isSelfClosing: false,
|
|
464
|
-
name: 'tag',
|
|
465
|
-
rawTag: '<tag>',
|
|
466
|
-
},
|
|
467
|
-
type: 'tagopen',
|
|
468
|
-
},
|
|
469
|
-
{
|
|
470
|
-
data: {
|
|
471
|
-
contents: 'before ',
|
|
472
|
-
},
|
|
473
|
-
type: 'text',
|
|
474
|
-
},
|
|
475
|
-
{
|
|
476
|
-
data: {
|
|
477
|
-
contents: '& after',
|
|
478
|
-
},
|
|
479
|
-
type: 'text',
|
|
480
|
-
},
|
|
481
|
-
{
|
|
482
|
-
data: {
|
|
483
|
-
name: 'tag',
|
|
484
|
-
rawTag: '</tag>',
|
|
485
|
-
},
|
|
486
|
-
type: 'tagclose',
|
|
487
|
-
},
|
|
488
|
-
]);
|
|
489
|
-
// The text content should be properly reconstructed
|
|
490
|
-
const textContent = events
|
|
491
|
-
.filter((e) => e.type === 'text')
|
|
492
|
-
.map((e) => e.data.contents)
|
|
493
|
-
.join('');
|
|
494
|
-
(0, bun_test_1.expect)(textContent).toBe('before & after');
|
|
495
|
-
});
|
|
496
|
-
(0, bun_test_1.it)('should handle multiple split entities in sequence', async () => {
|
|
497
|
-
const parser = new saxy_1.Saxy();
|
|
498
|
-
const events = [];
|
|
499
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
500
|
-
// Write chunks that split multiple entities
|
|
501
|
-
parser.write('Text with &am');
|
|
502
|
-
parser.write('p; and &l');
|
|
503
|
-
parser.write('t; symbols');
|
|
504
|
-
parser.end();
|
|
505
|
-
// The entities should be properly decoded and combined
|
|
506
|
-
(0, bun_test_1.expect)(events.map((e) => e.data.contents).join('')).toBe('Text with & and < symbols');
|
|
507
|
-
});
|
|
508
|
-
(0, bun_test_1.it)('should handle literal ampersand split across chunks', async () => {
|
|
509
|
-
const parser = new saxy_1.Saxy();
|
|
510
|
-
const events = [];
|
|
511
|
-
parser.on('text', (data) => {
|
|
512
|
-
events.push({ type: 'text', data });
|
|
513
|
-
});
|
|
514
|
-
parser.on('tagopen', (data) => events.push({ type: 'tagopen', data }));
|
|
515
|
-
parser.on('tagclose', (data) => events.push({ type: 'tagclose', data }));
|
|
516
|
-
// Write chunks that split a literal & character
|
|
517
|
-
parser.write('<tag>before &');
|
|
518
|
-
parser.write(' after</tag>');
|
|
519
|
-
parser.end();
|
|
520
|
-
// The & should be treated as literal text and stay with its surrounding content
|
|
521
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
522
|
-
{
|
|
523
|
-
data: {
|
|
524
|
-
attrs: '',
|
|
525
|
-
isSelfClosing: false,
|
|
526
|
-
name: 'tag',
|
|
527
|
-
rawTag: '<tag>',
|
|
528
|
-
},
|
|
529
|
-
type: 'tagopen',
|
|
530
|
-
},
|
|
531
|
-
{
|
|
532
|
-
data: {
|
|
533
|
-
contents: 'before ',
|
|
534
|
-
},
|
|
535
|
-
type: 'text',
|
|
536
|
-
},
|
|
537
|
-
{
|
|
538
|
-
data: {
|
|
539
|
-
contents: '& after',
|
|
540
|
-
},
|
|
541
|
-
type: 'text',
|
|
542
|
-
},
|
|
543
|
-
{
|
|
544
|
-
data: {
|
|
545
|
-
name: 'tag',
|
|
546
|
-
rawTag: '</tag>',
|
|
547
|
-
},
|
|
548
|
-
type: 'tagclose',
|
|
549
|
-
},
|
|
550
|
-
]);
|
|
551
|
-
// The text content should be properly reconstructed
|
|
552
|
-
const textContent = events
|
|
553
|
-
.filter((e) => e.type === 'text')
|
|
554
|
-
.map((e) => e.data.contents)
|
|
555
|
-
.join('');
|
|
556
|
-
(0, bun_test_1.expect)(textContent).toBe('before & after');
|
|
557
|
-
});
|
|
558
|
-
(0, bun_test_1.it)('should not treat standalone ampersand as pending entity', async () => {
|
|
559
|
-
const parser = new saxy_1.Saxy();
|
|
560
|
-
const events = [];
|
|
561
|
-
parser.on('text', (data) => {
|
|
562
|
-
events.push({ type: 'text', data });
|
|
563
|
-
});
|
|
564
|
-
// Write chunks that split a standalone & character
|
|
565
|
-
parser.write('Text with &');
|
|
566
|
-
parser.write(' more text');
|
|
567
|
-
parser.end();
|
|
568
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
569
|
-
{ type: 'text', data: { contents: 'Text with ' } },
|
|
570
|
-
{ type: 'text', data: { contents: '& more text' } },
|
|
571
|
-
]);
|
|
572
|
-
// The text content should be properly reconstructed
|
|
573
|
-
const textContent = events
|
|
574
|
-
.filter((e) => e.type === 'text')
|
|
575
|
-
.map((e) => e.data.contents)
|
|
576
|
-
.join('');
|
|
577
|
-
(0, bun_test_1.expect)(textContent).toBe('Text with & more text');
|
|
578
|
-
});
|
|
579
|
-
(0, bun_test_1.it)('should handle text split across chunks without entities or tags', async () => {
|
|
580
|
-
const parser = new saxy_1.Saxy();
|
|
581
|
-
const events = [];
|
|
582
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
583
|
-
parser.on('tagopen', (data) => events.push({ type: 'tagopen', data }));
|
|
584
|
-
parser.on('tagclose', (data) => events.push({ type: 'tagclose', data }));
|
|
585
|
-
// Write text split across chunks with no entities or tags
|
|
586
|
-
parser.write('<tag>Some text');
|
|
587
|
-
parser.write(' continued</tag>');
|
|
588
|
-
parser.end();
|
|
589
|
-
// The text content should be emitted in two chunks due to the new immediate emission behavior
|
|
590
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
591
|
-
{
|
|
592
|
-
data: {
|
|
593
|
-
attrs: '',
|
|
594
|
-
isSelfClosing: false,
|
|
595
|
-
name: 'tag',
|
|
596
|
-
rawTag: '<tag>',
|
|
597
|
-
},
|
|
598
|
-
type: 'tagopen',
|
|
599
|
-
},
|
|
600
|
-
{
|
|
601
|
-
data: {
|
|
602
|
-
contents: 'Some text',
|
|
603
|
-
},
|
|
604
|
-
type: 'text',
|
|
605
|
-
},
|
|
606
|
-
{
|
|
607
|
-
data: {
|
|
608
|
-
contents: ' continued',
|
|
609
|
-
},
|
|
610
|
-
type: 'text',
|
|
611
|
-
},
|
|
612
|
-
{
|
|
613
|
-
data: {
|
|
614
|
-
name: 'tag',
|
|
615
|
-
rawTag: '</tag>',
|
|
616
|
-
},
|
|
617
|
-
type: 'tagclose',
|
|
618
|
-
},
|
|
619
|
-
]);
|
|
620
|
-
// The text content should still be properly reconstructible
|
|
621
|
-
const textContent = events
|
|
622
|
-
.filter((e) => e.type === 'text')
|
|
623
|
-
.map((e) => e.data.contents)
|
|
624
|
-
.join('');
|
|
625
|
-
(0, bun_test_1.expect)(textContent).toBe('Some text continued');
|
|
626
|
-
});
|
|
627
|
-
(0, bun_test_1.it)('should output closing tag as text if not matching', async () => {
|
|
628
|
-
const parser = new saxy_1.Saxy();
|
|
629
|
-
const events = [];
|
|
630
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
631
|
-
parser.on('tagopen', (data) => events.push({ type: 'tagopen', data }));
|
|
632
|
-
parser.on('tagclose', (data) => events.push({ type: 'tagclose', data }));
|
|
633
|
-
// Write text split across chunks with no entities or tags
|
|
634
|
-
parser.write('<tag></invalid></tag>');
|
|
635
|
-
parser.end();
|
|
636
|
-
// The text content should be emitted in two chunks due to the new immediate emission behavior
|
|
637
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
638
|
-
{
|
|
639
|
-
data: {
|
|
640
|
-
attrs: '',
|
|
641
|
-
isSelfClosing: false,
|
|
642
|
-
name: 'tag',
|
|
643
|
-
rawTag: '<tag>',
|
|
644
|
-
},
|
|
645
|
-
type: 'tagopen',
|
|
646
|
-
},
|
|
647
|
-
{
|
|
648
|
-
data: {
|
|
649
|
-
name: 'invalid',
|
|
650
|
-
rawTag: '</invalid>',
|
|
651
|
-
},
|
|
652
|
-
type: 'tagclose',
|
|
653
|
-
},
|
|
654
|
-
{
|
|
655
|
-
data: {
|
|
656
|
-
name: 'tag',
|
|
657
|
-
rawTag: '</tag>',
|
|
658
|
-
},
|
|
659
|
-
type: 'tagclose',
|
|
660
|
-
},
|
|
661
|
-
]);
|
|
662
|
-
// The text content should still be properly reconstructible
|
|
663
|
-
const textContent = events
|
|
664
|
-
.filter((e) => e.type === 'text')
|
|
665
|
-
.map((e) => e.data.contents)
|
|
666
|
-
.join('');
|
|
667
|
-
(0, bun_test_1.expect)(textContent).toBe('');
|
|
668
|
-
});
|
|
669
|
-
});
|
|
670
|
-
(0, bun_test_1.describe)('shouldParseEntities = false', () => {
|
|
671
|
-
(0, bun_test_1.it)('should not parse HTML entities in text content when shouldParseEntities is false', () => {
|
|
672
|
-
const xml = '<tag>Text with & < entities</tag>';
|
|
673
|
-
const events = processXML(xml, undefined, false);
|
|
674
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
675
|
-
{
|
|
676
|
-
type: 'tagopen',
|
|
677
|
-
data: {
|
|
678
|
-
name: 'tag',
|
|
679
|
-
attrs: '',
|
|
680
|
-
isSelfClosing: false,
|
|
681
|
-
rawTag: '<tag>',
|
|
682
|
-
},
|
|
683
|
-
},
|
|
684
|
-
{
|
|
685
|
-
type: 'text',
|
|
686
|
-
data: { contents: 'Text with & < entities' },
|
|
687
|
-
},
|
|
688
|
-
{
|
|
689
|
-
type: 'tagclose',
|
|
690
|
-
data: {
|
|
691
|
-
name: 'tag',
|
|
692
|
-
rawTag: '</tag>',
|
|
693
|
-
},
|
|
694
|
-
},
|
|
695
|
-
]);
|
|
696
|
-
});
|
|
697
|
-
(0, bun_test_1.it)('should not parse HTML entities split across chunks when shouldParseEntities is false', () => {
|
|
698
|
-
const parser = new saxy_1.Saxy(undefined, false);
|
|
699
|
-
const events = [];
|
|
700
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
701
|
-
parser.on('tagopen', (data) => events.push({ type: 'tagopen', data }));
|
|
702
|
-
parser.on('tagclose', (data) => events.push({ type: 'tagclose', data }));
|
|
703
|
-
parser.write('<tag>Text with &am');
|
|
704
|
-
parser.write('p; and &l');
|
|
705
|
-
parser.write('t; entities</tag>');
|
|
706
|
-
parser.end();
|
|
707
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
708
|
-
{
|
|
709
|
-
type: 'tagopen',
|
|
710
|
-
data: {
|
|
711
|
-
name: 'tag',
|
|
712
|
-
attrs: '',
|
|
713
|
-
isSelfClosing: false,
|
|
714
|
-
rawTag: '<tag>',
|
|
715
|
-
},
|
|
716
|
-
},
|
|
717
|
-
{
|
|
718
|
-
type: 'text',
|
|
719
|
-
data: { contents: 'Text with &am' },
|
|
720
|
-
},
|
|
721
|
-
{
|
|
722
|
-
type: 'text',
|
|
723
|
-
data: { contents: 'p; and &l' },
|
|
724
|
-
},
|
|
725
|
-
{
|
|
726
|
-
type: 'text',
|
|
727
|
-
data: { contents: 't; entities' },
|
|
728
|
-
},
|
|
729
|
-
{
|
|
730
|
-
type: 'tagclose',
|
|
731
|
-
data: {
|
|
732
|
-
name: 'tag',
|
|
733
|
-
rawTag: '</tag>',
|
|
734
|
-
},
|
|
735
|
-
},
|
|
736
|
-
]);
|
|
737
|
-
(0, bun_test_1.expect)(events
|
|
738
|
-
.filter((e) => e.type === 'text')
|
|
739
|
-
.map((e) => e.data.contents)
|
|
740
|
-
.join('')).toEqual('Text with & and < entities');
|
|
741
|
-
});
|
|
742
|
-
(0, bun_test_1.it)('should handle text nodes correctly in _final when shouldParseEntities is false', () => {
|
|
743
|
-
const parser = new saxy_1.Saxy(undefined, false);
|
|
744
|
-
const events = [];
|
|
745
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
746
|
-
// Write text that would normally be parsed if shouldParseEntities was true
|
|
747
|
-
parser.write('Final text with & < entities');
|
|
748
|
-
parser.end(); // _final will be called here
|
|
749
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
750
|
-
{
|
|
751
|
-
type: 'text',
|
|
752
|
-
data: { contents: 'Final text with & < entities' },
|
|
753
|
-
},
|
|
754
|
-
]);
|
|
755
|
-
});
|
|
756
|
-
});
|
|
757
|
-
(0, bun_test_1.describe)('Real World Examples', () => {
|
|
758
|
-
(0, bun_test_1.it)('should handle && ( <', () => {
|
|
759
|
-
const parser = new saxy_1.Saxy();
|
|
760
|
-
const events = [];
|
|
761
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
762
|
-
parser.on('tagopen', (data) => events.push({ type: 'tagopen', data }));
|
|
763
|
-
parser.on('tagclose', (data) => events.push({ type: 'tagclose', data }));
|
|
764
|
-
// Write text split across chunks with no entities or tags
|
|
765
|
-
parser.write('<write_file>\n<path>path/to/file</path>\n<content>testing && ( <div className="flex flex-col"></content>\n</write_file>');
|
|
766
|
-
parser.end();
|
|
767
|
-
// The text content should be emitted in two chunks due to the new immediate emission behavior
|
|
768
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
769
|
-
{
|
|
770
|
-
data: {
|
|
771
|
-
attrs: '',
|
|
772
|
-
isSelfClosing: false,
|
|
773
|
-
name: 'write_file',
|
|
774
|
-
rawTag: '<write_file>',
|
|
775
|
-
},
|
|
776
|
-
type: 'tagopen',
|
|
777
|
-
},
|
|
778
|
-
{
|
|
779
|
-
data: {
|
|
780
|
-
attrs: '',
|
|
781
|
-
isSelfClosing: false,
|
|
782
|
-
name: 'path',
|
|
783
|
-
rawTag: '<path>',
|
|
784
|
-
},
|
|
785
|
-
type: 'tagopen',
|
|
786
|
-
},
|
|
787
|
-
{
|
|
788
|
-
data: {
|
|
789
|
-
contents: 'path/to/file',
|
|
790
|
-
},
|
|
791
|
-
type: 'text',
|
|
792
|
-
},
|
|
793
|
-
{
|
|
794
|
-
data: {
|
|
795
|
-
name: 'path',
|
|
796
|
-
rawTag: '</path>',
|
|
797
|
-
},
|
|
798
|
-
type: 'tagclose',
|
|
799
|
-
},
|
|
800
|
-
{
|
|
801
|
-
data: {
|
|
802
|
-
attrs: '',
|
|
803
|
-
isSelfClosing: false,
|
|
804
|
-
name: 'content',
|
|
805
|
-
rawTag: '<content>',
|
|
806
|
-
},
|
|
807
|
-
type: 'tagopen',
|
|
808
|
-
},
|
|
809
|
-
{
|
|
810
|
-
data: {
|
|
811
|
-
contents: 'testing && ( <div className="flex flex-col">',
|
|
812
|
-
},
|
|
813
|
-
type: 'text',
|
|
814
|
-
},
|
|
815
|
-
{
|
|
816
|
-
data: {
|
|
817
|
-
name: 'content',
|
|
818
|
-
rawTag: '</content>',
|
|
819
|
-
},
|
|
820
|
-
type: 'tagclose',
|
|
821
|
-
},
|
|
822
|
-
{
|
|
823
|
-
data: {
|
|
824
|
-
name: 'write_file',
|
|
825
|
-
rawTag: '</write_file>',
|
|
826
|
-
},
|
|
827
|
-
type: 'tagclose',
|
|
828
|
-
},
|
|
829
|
-
]);
|
|
830
|
-
});
|
|
831
|
-
(0, bun_test_1.it)('should handle entity at end of content', () => {
|
|
832
|
-
const parser = new saxy_1.Saxy();
|
|
833
|
-
const events = [];
|
|
834
|
-
parser.on('text', (data) => events.push({ type: 'text', data }));
|
|
835
|
-
parser.on('tagopen', (data) => events.push({ type: 'tagopen', data }));
|
|
836
|
-
parser.on('tagclose', (data) => events.push({ type: 'tagclose', data }));
|
|
837
|
-
// Write text split across chunks with no entities or tags
|
|
838
|
-
parser.write(`<write_file>\n<path>path/to/file</path>\n<content>some value &</content>\n</write_file>`);
|
|
839
|
-
parser.end();
|
|
840
|
-
// The text content should be emitted in two chunks due to the new immediate emission behavior
|
|
841
|
-
(0, bun_test_1.expect)(events).toEqual([
|
|
842
|
-
{
|
|
843
|
-
data: {
|
|
844
|
-
attrs: '',
|
|
845
|
-
isSelfClosing: false,
|
|
846
|
-
name: 'write_file',
|
|
847
|
-
rawTag: '<write_file>',
|
|
848
|
-
},
|
|
849
|
-
type: 'tagopen',
|
|
850
|
-
},
|
|
851
|
-
{
|
|
852
|
-
data: {
|
|
853
|
-
attrs: '',
|
|
854
|
-
isSelfClosing: false,
|
|
855
|
-
name: 'path',
|
|
856
|
-
rawTag: '<path>',
|
|
857
|
-
},
|
|
858
|
-
type: 'tagopen',
|
|
859
|
-
},
|
|
860
|
-
{
|
|
861
|
-
data: {
|
|
862
|
-
contents: 'path/to/file',
|
|
863
|
-
},
|
|
864
|
-
type: 'text',
|
|
865
|
-
},
|
|
866
|
-
{
|
|
867
|
-
data: {
|
|
868
|
-
name: 'path',
|
|
869
|
-
rawTag: '</path>',
|
|
870
|
-
},
|
|
871
|
-
type: 'tagclose',
|
|
872
|
-
},
|
|
873
|
-
{
|
|
874
|
-
data: {
|
|
875
|
-
attrs: '',
|
|
876
|
-
isSelfClosing: false,
|
|
877
|
-
name: 'content',
|
|
878
|
-
rawTag: '<content>',
|
|
879
|
-
},
|
|
880
|
-
type: 'tagopen',
|
|
881
|
-
},
|
|
882
|
-
{
|
|
883
|
-
data: {
|
|
884
|
-
contents: 'some value &',
|
|
885
|
-
},
|
|
886
|
-
type: 'text',
|
|
887
|
-
},
|
|
888
|
-
{
|
|
889
|
-
data: {
|
|
890
|
-
name: 'content',
|
|
891
|
-
rawTag: '</content>',
|
|
892
|
-
},
|
|
893
|
-
type: 'tagclose',
|
|
894
|
-
},
|
|
895
|
-
{
|
|
896
|
-
data: {
|
|
897
|
-
name: 'write_file',
|
|
898
|
-
rawTag: '</write_file>',
|
|
899
|
-
},
|
|
900
|
-
type: 'tagclose',
|
|
901
|
-
},
|
|
902
|
-
]);
|
|
903
|
-
});
|
|
904
|
-
});
|
|
905
|
-
});
|
|
906
|
-
//# sourceMappingURL=saxy.test.js.map
|