svelte-rtf-editor 1.8.1 → 1.8.2
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/rtf-parser.js +16 -1
- package/package.json +1 -1
package/dist/rtf-parser.js
CHANGED
|
@@ -277,18 +277,33 @@ function tokenize(rtf) {
|
|
|
277
277
|
return tokens;
|
|
278
278
|
}
|
|
279
279
|
// ── AST Builder ──
|
|
280
|
+
/**
|
|
281
|
+
* The deepest group the tree holds. The renderer walks groups recursively, and thousands of
|
|
282
|
+
* nested groups (damaged or hostile input) would overflow the stack; real documents nest a few
|
|
283
|
+
* dozen deep at most. Groups below this depth are folded into the one at it: their text is kept,
|
|
284
|
+
* and their formatting carries on to the end of that group.
|
|
285
|
+
*/
|
|
286
|
+
const MAX_GROUP_DEPTH = 500;
|
|
280
287
|
function buildTree(tokens) {
|
|
281
288
|
const root = { type: 'group', children: [] };
|
|
282
289
|
const stack = [root];
|
|
290
|
+
/** Groups opened past MAX_GROUP_DEPTH and not closed yet. */
|
|
291
|
+
let folded = 0;
|
|
283
292
|
for (const tok of tokens) {
|
|
284
293
|
const current = stack[stack.length - 1];
|
|
285
294
|
if (tok.type === 'open') {
|
|
295
|
+
if (stack.length > MAX_GROUP_DEPTH) {
|
|
296
|
+
folded++;
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
286
299
|
const group = { type: 'group', children: [] };
|
|
287
300
|
current.children.push(group);
|
|
288
301
|
stack.push(group);
|
|
289
302
|
}
|
|
290
303
|
else if (tok.type === 'close') {
|
|
291
|
-
if (
|
|
304
|
+
if (folded > 0)
|
|
305
|
+
folded--;
|
|
306
|
+
else if (stack.length > 1)
|
|
292
307
|
stack.pop();
|
|
293
308
|
}
|
|
294
309
|
else if (tok.type === 'control') {
|
package/package.json
CHANGED