fabric 6.8.0 → 6.9.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/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## [next]
4
4
 
5
+ ## [6.9.0]
6
+
7
+ - fix(): Prototype pollution risk on text char cache [#10782](https://github.com/fabricjs/fabric.js/pull/10782)
8
+
5
9
  ## [6.8.0]
6
10
 
7
11
  - fix(): CWE-1333 CWE-400 CWE-730 Simplify some regexes in order to avoid slowness with craft bad string #10746
package/dist/index.js CHANGED
@@ -337,11 +337,11 @@
337
337
  };
338
338
 
339
339
  class Cache {
340
+ /**
341
+ * Cache of widths of chars in text rendering.
342
+ */
343
+
340
344
  constructor() {
341
- /**
342
- * Cache of widths of chars in text rendering.
343
- */
344
- _defineProperty(this, "charWidthsCache", {});
345
345
  /**
346
346
  * This object keeps the results of the boundsOfCurve calculation mapped by the joined arguments necessary to calculate it.
347
347
  * It does speed up calculation, if you parse and add always the same paths, but in case of heavy usage of freedrawing
@@ -351,7 +351,9 @@
351
351
  * It was an internal variable, is accessible since version 2.3.4
352
352
  */
353
353
  _defineProperty(this, "boundsOfCurveCache", {});
354
+ this.charWidthsCache = new Map();
354
355
  }
356
+
355
357
  /**
356
358
  * @return {Object} reference to cache
357
359
  */
@@ -362,15 +364,16 @@
362
364
  fontWeight
363
365
  } = _ref;
364
366
  fontFamily = fontFamily.toLowerCase();
365
- if (!this.charWidthsCache[fontFamily]) {
366
- this.charWidthsCache[fontFamily] = {};
367
+ const cache = this.charWidthsCache;
368
+ if (!cache.has(fontFamily)) {
369
+ cache.set(fontFamily, new Map());
367
370
  }
368
- const fontCache = this.charWidthsCache[fontFamily];
371
+ const fontCache = cache.get(fontFamily);
369
372
  const cacheKey = "".concat(fontStyle.toLowerCase(), "_").concat((fontWeight + '').toLowerCase());
370
- if (!fontCache[cacheKey]) {
371
- fontCache[cacheKey] = {};
373
+ if (!fontCache.has(cacheKey)) {
374
+ fontCache.set(cacheKey, new Map());
372
375
  }
373
- return fontCache[cacheKey];
376
+ return fontCache.get(cacheKey);
374
377
  }
375
378
 
376
379
  /**
@@ -385,11 +388,10 @@
385
388
  * @param {String} [fontFamily] font family to clear
386
389
  */
387
390
  clearFontCache(fontFamily) {
388
- fontFamily = (fontFamily || '').toLowerCase();
389
391
  if (!fontFamily) {
390
- this.charWidthsCache = {};
391
- } else if (this.charWidthsCache[fontFamily]) {
392
- delete this.charWidthsCache[fontFamily];
392
+ this.charWidthsCache = new Map();
393
+ } else {
394
+ this.charWidthsCache.delete((fontFamily || '').toLowerCase());
393
395
  }
394
396
  }
395
397
 
@@ -411,7 +413,7 @@
411
413
  }
412
414
  const cache = new Cache();
413
415
 
414
- var version = "6.8.0";
416
+ var version = "6.9.0";
415
417
 
416
418
  // use this syntax so babel plugin see this import here
417
419
  const VERSION = version;
@@ -19379,14 +19381,14 @@
19379
19381
  stylesAreEqual = previousChar && fontDeclaration === this._getFontDeclaration(prevCharStyle),
19380
19382
  fontMultiplier = charStyle.fontSize / this.CACHE_FONT_SIZE;
19381
19383
  let width, coupleWidth, previousWidth, kernedWidth;
19382
- if (previousChar && fontCache[previousChar] !== undefined) {
19383
- previousWidth = fontCache[previousChar];
19384
+ if (previousChar && fontCache.has(previousChar)) {
19385
+ previousWidth = fontCache.get(previousChar);
19384
19386
  }
19385
- if (fontCache[_char] !== undefined) {
19386
- kernedWidth = width = fontCache[_char];
19387
+ if (fontCache.has(_char)) {
19388
+ kernedWidth = width = fontCache.get(_char);
19387
19389
  }
19388
- if (stylesAreEqual && fontCache[couple] !== undefined) {
19389
- coupleWidth = fontCache[couple];
19390
+ if (stylesAreEqual && fontCache.has(couple)) {
19391
+ coupleWidth = fontCache.get(couple);
19390
19392
  kernedWidth = coupleWidth - previousWidth;
19391
19393
  }
19392
19394
  if (width === undefined || previousWidth === undefined || coupleWidth === undefined) {
@@ -19395,16 +19397,16 @@
19395
19397
  this._setTextStyles(ctx, charStyle, true);
19396
19398
  if (width === undefined) {
19397
19399
  kernedWidth = width = ctx.measureText(_char).width;
19398
- fontCache[_char] = width;
19400
+ fontCache.set(_char, width);
19399
19401
  }
19400
19402
  if (previousWidth === undefined && stylesAreEqual && previousChar) {
19401
19403
  previousWidth = ctx.measureText(previousChar).width;
19402
- fontCache[previousChar] = previousWidth;
19404
+ fontCache.set(previousChar, previousWidth);
19403
19405
  }
19404
19406
  if (stylesAreEqual && coupleWidth === undefined) {
19405
19407
  // we can measure the kerning couple and subtract the width of the previous character
19406
19408
  coupleWidth = ctx.measureText(couple).width;
19407
- fontCache[couple] = coupleWidth;
19409
+ fontCache.set(couple, coupleWidth);
19408
19410
  // safe to use the non-null since if undefined we defined it before.
19409
19411
  kernedWidth = coupleWidth - previousWidth;
19410
19412
  }