@patrickdk77/office-defuse 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +230 -2
- package/dist/context.d.ts +38 -0
- package/dist/context.js +100 -0
- package/dist/crc32.d.ts +2 -0
- package/dist/crc32.js +18 -0
- package/dist/engine.d.ts +5 -0
- package/dist/engine.js +151 -0
- package/dist/errors.d.ts +19 -0
- package/dist/errors.js +33 -0
- package/dist/findings.d.ts +25 -0
- package/dist/findings.js +169 -0
- package/dist/formats.d.ts +10 -0
- package/dist/formats.js +46 -0
- package/dist/formulas.d.ts +22 -0
- package/dist/formulas.js +77 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +30 -0
- package/dist/index.mjs +3 -0
- package/dist/io.d.ts +23 -0
- package/dist/io.js +139 -0
- package/dist/links.d.ts +26 -0
- package/dist/links.js +145 -0
- package/dist/odf.d.ts +3 -0
- package/dist/odf.js +297 -0
- package/dist/ooxml.d.ts +8 -0
- package/dist/ooxml.js +516 -0
- package/dist/score.d.ts +17 -0
- package/dist/score.js +63 -0
- package/dist/types.d.ts +247 -0
- package/dist/types.js +133 -0
- package/dist/xlsb.d.ts +19 -0
- package/dist/xlsb.js +101 -0
- package/dist/xml.d.ts +256 -0
- package/dist/xml.js +1105 -0
- package/dist/zip-writer.d.ts +38 -0
- package/dist/zip-writer.js +182 -0
- package/dist/zip.d.ts +55 -0
- package/dist/zip.js +535 -0
- package/package.json +96 -4
package/dist/xml.d.ts
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
export declare const XML_NS = "http://www.w3.org/XML/1998/namespace";
|
|
2
|
+
export declare const XMLNS_NS = "http://www.w3.org/2000/xmlns/";
|
|
3
|
+
/**
|
|
4
|
+
* Stands in text for a reference to an external entity, whose content office-defuse never fetches: UNKNOWN, the
|
|
5
|
+
* entity's name, UNKNOWN again. U+FFFF cannot occur in XML, so nothing a part holds is taken for it.
|
|
6
|
+
*/
|
|
7
|
+
export declare const UNKNOWN: string;
|
|
8
|
+
/** A value with each reference to an external entity written back as `&name;`, for a finding to show. */
|
|
9
|
+
export declare const showReferences: (s: string) => string;
|
|
10
|
+
/** The name of the first external entity whose content stands in `s`, or undefined when none does. */
|
|
11
|
+
export declare const unknownEntity: (s: string) => string | undefined;
|
|
12
|
+
export interface XmlAttribute {
|
|
13
|
+
/** Namespace URI, '' for none. */
|
|
14
|
+
ns: string;
|
|
15
|
+
local: string;
|
|
16
|
+
qname: string;
|
|
17
|
+
/** Normalized value, with references expanded. An attribute-list declaration can give it a default or normalize it further. */
|
|
18
|
+
value: string;
|
|
19
|
+
}
|
|
20
|
+
export interface XmlElement {
|
|
21
|
+
/** Namespace URI, '' for none. */
|
|
22
|
+
ns: string;
|
|
23
|
+
local: string;
|
|
24
|
+
qname: string;
|
|
25
|
+
/** Attributes other than namespace declarations. */
|
|
26
|
+
attributes: XmlAttribute[];
|
|
27
|
+
/** 1 for the root element. */
|
|
28
|
+
depth: number;
|
|
29
|
+
/**
|
|
30
|
+
* Offsets of the start tag in the decoded text, end exclusive. An element from an entity's text has the offsets of
|
|
31
|
+
* the reference to that entity in the part, or of the outermost one when references nest.
|
|
32
|
+
*/
|
|
33
|
+
start: number;
|
|
34
|
+
end: number;
|
|
35
|
+
}
|
|
36
|
+
export interface XmlHandler {
|
|
37
|
+
start?(el: XmlElement): void;
|
|
38
|
+
/** `start` and `end` are the offsets of the end tag, or of the start tag again for an empty element. */
|
|
39
|
+
end?(el: XmlElement, start: number, end: number): void;
|
|
40
|
+
/** Character data and CDATA content, decoded, in pieces of any size. A reference to an external entity comes as one piece. */
|
|
41
|
+
text?(text: string): void;
|
|
42
|
+
}
|
|
43
|
+
export interface XmlLimits {
|
|
44
|
+
depth: number;
|
|
45
|
+
tokenSize: number;
|
|
46
|
+
/** Entity references nested inside entity text. */
|
|
47
|
+
entityDepth: number;
|
|
48
|
+
/** Entity references expanded, counted in the budget. */
|
|
49
|
+
entityExpansions: number;
|
|
50
|
+
/** Characters of entity text expanded, counted in the budget. */
|
|
51
|
+
entitySize: number;
|
|
52
|
+
}
|
|
53
|
+
/** Entity expansion so far. One inspection shares it among its parts, so the limits bound the whole package. */
|
|
54
|
+
export interface EntityBudget {
|
|
55
|
+
expansions: number;
|
|
56
|
+
size: number;
|
|
57
|
+
}
|
|
58
|
+
/** A document type declaration. */
|
|
59
|
+
export interface XmlDoctype {
|
|
60
|
+
/** The root element type it names. */
|
|
61
|
+
name: string;
|
|
62
|
+
publicId?: string;
|
|
63
|
+
systemId?: string;
|
|
64
|
+
/** Whether it has an internal subset, declarations between square brackets. */
|
|
65
|
+
internalSubset: boolean;
|
|
66
|
+
/** General entities the internal subset declares, and how many of them are external. */
|
|
67
|
+
entities: number;
|
|
68
|
+
externalEntities: number;
|
|
69
|
+
/** Attribute defaults the internal subset declares. */
|
|
70
|
+
attributeDefaults: number;
|
|
71
|
+
/** Entity and attribute-list declarations skipped after a parameter entity that was not read. */
|
|
72
|
+
skipped: number;
|
|
73
|
+
/** Offsets of the declaration in the decoded text, end exclusive. */
|
|
74
|
+
start: number;
|
|
75
|
+
end: number;
|
|
76
|
+
}
|
|
77
|
+
/** A reference to an external entity in content, which is never fetched. */
|
|
78
|
+
export interface XmlExternalReference {
|
|
79
|
+
name: string;
|
|
80
|
+
publicId?: string;
|
|
81
|
+
systemId: string;
|
|
82
|
+
/** Offsets of the reference in the decoded text, or of the outermost reference whose entity text holds it. */
|
|
83
|
+
start: number;
|
|
84
|
+
end: number;
|
|
85
|
+
}
|
|
86
|
+
/** What the tokenizer reports besides elements and text. */
|
|
87
|
+
export interface XmlNotes {
|
|
88
|
+
doctype?(d: XmlDoctype): void;
|
|
89
|
+
externalEntity?(r: XmlExternalReference): void;
|
|
90
|
+
}
|
|
91
|
+
export interface XmlOptions {
|
|
92
|
+
/** Reads the dialect Office writes in VML drawing parts. See XmlTokenizer. */
|
|
93
|
+
vml?: boolean;
|
|
94
|
+
notes?: XmlNotes;
|
|
95
|
+
/** Shared with the other parts of a package. A tokenizer without one counts on its own. */
|
|
96
|
+
budget?: EntityBudget;
|
|
97
|
+
}
|
|
98
|
+
/** The value of the attribute with this namespace and local name. */
|
|
99
|
+
export declare function attr(el: XmlElement, ns: string, local: string): string | undefined;
|
|
100
|
+
/** An XML name without a colon. */
|
|
101
|
+
export declare const isNcName: (s: string) => boolean;
|
|
102
|
+
/**
|
|
103
|
+
* A streaming XML 1.0 tokenizer with namespaces. It refuses references to entities nothing declares, encodings other
|
|
104
|
+
* than UTF-8 and UTF-16, and anything not well-formed. It holds one markup token at a time; text goes to the handler
|
|
105
|
+
* in pieces.
|
|
106
|
+
*
|
|
107
|
+
* A document type declaration goes to `notes.doctype`. No external DTD or other external entity is ever loaded. The
|
|
108
|
+
* internal subset is read as XML 1.0 (5.1) has a processor read it that reads internal parameter entities and no
|
|
109
|
+
* external ones: it keeps the general entities and attribute-list declarations, reads the text of each internal
|
|
110
|
+
* parameter entity it refers to, and skips the entity and attribute-list declarations after a parameter entity it
|
|
111
|
+
* does not read, unless the XML declaration says standalone="yes".
|
|
112
|
+
*
|
|
113
|
+
* A reference to an internal entity is expanded, within the entity limits, and the handler sees its text, markup
|
|
114
|
+
* included, as if the part held it. A reference to an external entity in content goes to `notes.externalEntity`, and
|
|
115
|
+
* stands in the text as UNKNOWN marks it. One in an attribute value, directly or through other entities, is refused,
|
|
116
|
+
* as XML 1.0 refuses it. An attribute an element leaves out gets the default its attribute-list declaration gives, and
|
|
117
|
+
* an attribute declared with a type other than CDATA is normalized further, as expat does. Each default added counts
|
|
118
|
+
* as an expansion against the entity limits.
|
|
119
|
+
*/
|
|
120
|
+
export declare class XmlTokenizer {
|
|
121
|
+
private readonly handler;
|
|
122
|
+
private readonly limits;
|
|
123
|
+
private readonly part;
|
|
124
|
+
private decoder?;
|
|
125
|
+
private head;
|
|
126
|
+
private buf;
|
|
127
|
+
private pos;
|
|
128
|
+
/** Offset in the decoded text of buf[0]. */
|
|
129
|
+
private base;
|
|
130
|
+
private readonly stack;
|
|
131
|
+
private rootSeen;
|
|
132
|
+
private doctypeSeen;
|
|
133
|
+
/** The XML declaration says standalone="yes". */
|
|
134
|
+
private standalone;
|
|
135
|
+
private encoding;
|
|
136
|
+
/** The last text piece ended in CR, so an LF that starts the next piece belongs to the same line end. */
|
|
137
|
+
private lastCr;
|
|
138
|
+
private scan?;
|
|
139
|
+
/** General entities the internal subset declares, by name. */
|
|
140
|
+
private readonly entities;
|
|
141
|
+
/** Parameter entities the internal subset declares, by name. */
|
|
142
|
+
private readonly parameters;
|
|
143
|
+
/** What the attribute-list declarations say, by element type as written. */
|
|
144
|
+
private readonly declared;
|
|
145
|
+
/** The entities being expanded, outermost first. A parameter entity's name has "%" in front. */
|
|
146
|
+
private readonly active;
|
|
147
|
+
/** While entity text is read, the offsets of the outermost reference, which its elements report. */
|
|
148
|
+
private span?;
|
|
149
|
+
/** The stack depth at which the entity text being read started. Its end tags close nothing below it. */
|
|
150
|
+
private floor;
|
|
151
|
+
private readonly vml;
|
|
152
|
+
private readonly notes;
|
|
153
|
+
private readonly budget;
|
|
154
|
+
/**
|
|
155
|
+
* `options.vml` reads the dialect Office writes in VML drawing parts, which is not well-formed XML: it skips the
|
|
156
|
+
* `<![if ...]>` and `<![endif]>` markers around content and takes an unclosed `<br>` as an empty element. Both
|
|
157
|
+
* branches of a marker reach the handler.
|
|
158
|
+
*/
|
|
159
|
+
constructor(handler: XmlHandler, limits: XmlLimits, part: string, options?: XmlOptions);
|
|
160
|
+
private stop;
|
|
161
|
+
private malformed;
|
|
162
|
+
write(bytes: Uint8Array): void;
|
|
163
|
+
end(): void;
|
|
164
|
+
/** Picks the encoding from the first bytes, as XML 1.0 Appendix F does, and reads the bytes held so far. */
|
|
165
|
+
private begin;
|
|
166
|
+
private decode;
|
|
167
|
+
/** Checks the XML declaration against the encoding the bytes are in, and notes whether it says standalone="yes". */
|
|
168
|
+
private declaration;
|
|
169
|
+
private feed;
|
|
170
|
+
/** Reads the text and markup in buf from pos. Entity text is read with `final` set, since all of it is there. */
|
|
171
|
+
private loop;
|
|
172
|
+
/** The offset in the decoded text of buf[i], or while entity text is read, that of the reference to it. */
|
|
173
|
+
private at;
|
|
174
|
+
/**
|
|
175
|
+
* Character data at `offset` in the decoded text. References are expanded and line ends turned into LF. Entity
|
|
176
|
+
* text had its line ends normalized where it was declared, so a CR in it, which only a character reference makes,
|
|
177
|
+
* stays.
|
|
178
|
+
*/
|
|
179
|
+
private text;
|
|
180
|
+
/** Hands decoded text to the handler. Outside the root element only white space may stand. */
|
|
181
|
+
private characters;
|
|
182
|
+
/**
|
|
183
|
+
* Normalizes an attribute value as XML 1.0 (3.3.3) says: references expanded, and each white space character a
|
|
184
|
+
* space, except one written as a character reference. `normalized` marks entity text, whose line ends were
|
|
185
|
+
* normalized where it was declared, so a CR and LF in it are two characters.
|
|
186
|
+
*/
|
|
187
|
+
private attributeValue;
|
|
188
|
+
/** The text a predefined entity or a character reference stands for, or undefined for any other entity. */
|
|
189
|
+
private plainReference;
|
|
190
|
+
private characterReference;
|
|
191
|
+
/** The entity a reference names. A reference to one nothing declares is refused. */
|
|
192
|
+
private entity;
|
|
193
|
+
/** Starts expanding an entity, within the limits. */
|
|
194
|
+
private enter;
|
|
195
|
+
/**
|
|
196
|
+
* Counts one expansion of `size` characters of declared text, an entity's or an attribute default's, against the
|
|
197
|
+
* limits, so a document type cannot make the part cost more than they allow.
|
|
198
|
+
*/
|
|
199
|
+
private charge;
|
|
200
|
+
/** A reference to a general entity in content. Its text is read as content, in place of the reference. */
|
|
201
|
+
private contentReference;
|
|
202
|
+
/** A reference to a general entity in an attribute value. Its text is normalized into the value. */
|
|
203
|
+
private attributeReference;
|
|
204
|
+
/** Reads one markup token at pos. Returns false when the buffer does not yet hold all of it. */
|
|
205
|
+
private markup;
|
|
206
|
+
private wait;
|
|
207
|
+
private advance;
|
|
208
|
+
private checkChars;
|
|
209
|
+
private instruction;
|
|
210
|
+
/**
|
|
211
|
+
* Finds the end of the document type declaration at p: the ">" outside its literals and its internal subset, where
|
|
212
|
+
* comments, processing instructions and declarations may hold either. Returns the offset after it, or -1 when buf
|
|
213
|
+
* does not hold all of it yet. The scan goes on from where it stopped.
|
|
214
|
+
*/
|
|
215
|
+
private scanDoctype;
|
|
216
|
+
/** Reads a whole document type declaration, keeping the entities and attributes its internal subset declares. */
|
|
217
|
+
private doctype;
|
|
218
|
+
/** SYSTEM and a system literal, or PUBLIC and a public and a system literal, or undefined when neither is next. */
|
|
219
|
+
private externalId;
|
|
220
|
+
/**
|
|
221
|
+
* Reads markup declarations: the internal subset up to and past its "]", or with `nested` the whole text of a
|
|
222
|
+
* parameter entity.
|
|
223
|
+
*/
|
|
224
|
+
private declarations;
|
|
225
|
+
/**
|
|
226
|
+
* A parameter entity reference between declarations. An internal entity's text is read as declarations, with a
|
|
227
|
+
* space on each side as XML 1.0 (4.4.8) says. An external or undeclared one is not read, and the entity and
|
|
228
|
+
* attribute-list declarations after it are skipped, since it could have declared the same names first.
|
|
229
|
+
*/
|
|
230
|
+
private parameterReference;
|
|
231
|
+
/**
|
|
232
|
+
* Reads an entity declaration after its keyword, and keeps the entity unless it comes after a parameter entity that
|
|
233
|
+
* was not read, or gives one of the predefined names, or a name already declared: the first declaration binds.
|
|
234
|
+
*/
|
|
235
|
+
private entityDeclaration;
|
|
236
|
+
/**
|
|
237
|
+
* The text an entity value expands to: line ends normalized, unless `normalized` says they were, and character
|
|
238
|
+
* references replaced. References to general entities stay as written, to be expanded where the entity is used. A
|
|
239
|
+
* parameter entity reference cannot stand inside a declaration in the internal subset.
|
|
240
|
+
*/
|
|
241
|
+
private entityValue;
|
|
242
|
+
/**
|
|
243
|
+
* Reads an attribute-list declaration after its keyword. Each attribute it names for the first time is kept, with
|
|
244
|
+
* its default normalized now, as the entities declared so far give it. After a parameter entity that was not read,
|
|
245
|
+
* the declaration is skipped.
|
|
246
|
+
*/
|
|
247
|
+
private attributeListDeclaration;
|
|
248
|
+
/** Reads an attribute type and tells whether its values are tokens, normalized further than CDATA. */
|
|
249
|
+
private attributeType;
|
|
250
|
+
/** An enumerated type: name tokens between parentheses, separated by "|". */
|
|
251
|
+
private enumeration;
|
|
252
|
+
private lookup;
|
|
253
|
+
private split;
|
|
254
|
+
private startTag;
|
|
255
|
+
private endTag;
|
|
256
|
+
}
|