svelte-rtf-editor 1.8.1 → 1.8.3

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.
Files changed (2) hide show
  1. package/dist/rtf-parser.js +21 -4
  2. package/package.json +1 -1
@@ -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 (stack.length > 1)
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') {
@@ -314,16 +329,18 @@ function parseColorTable(group) {
314
329
  }
315
330
  for (const node of group.children) {
316
331
  if (node.type === 'control') {
332
+ // A component outside 0 to 255 is damaged: it is held to the nearest end of the range.
333
+ const value = Math.min(255, Math.max(0, node.param ?? 0));
317
334
  if (node.word === 'red') {
318
- r = node.param ?? 0;
335
+ r = value;
319
336
  hasComponents = true;
320
337
  }
321
338
  else if (node.word === 'green') {
322
- g = node.param ?? 0;
339
+ g = value;
323
340
  hasComponents = true;
324
341
  }
325
342
  else if (node.word === 'blue') {
326
- b = node.param ?? 0;
343
+ b = value;
327
344
  hasComponents = true;
328
345
  }
329
346
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-rtf-editor",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
4
4
  "description": "RTF viewer and rich-text editor components for Svelte 5",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/jcelano/svelte-rtf-editor#readme",