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 +4 -0
- package/dist/index.js +26 -24
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.min.mjs +1 -1
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +26 -24
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +26 -24
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +26 -24
- package/dist/index.node.mjs.map +1 -1
- package/dist/package.json.min.mjs +1 -1
- package/dist/package.json.mjs +1 -1
- package/dist/src/cache.d.ts +6 -4
- package/dist/src/cache.d.ts.map +1 -1
- package/dist/src/cache.min.mjs +1 -1
- package/dist/src/cache.min.mjs.map +1 -1
- package/dist/src/cache.mjs +16 -14
- package/dist/src/cache.mjs.map +1 -1
- package/dist/src/shapes/Text/Text.min.mjs +1 -1
- package/dist/src/shapes/Text/Text.min.mjs.map +1 -1
- package/dist/src/shapes/Text/Text.mjs +9 -9
- package/dist/src/shapes/Text/Text.mjs.map +1 -1
- package/dist-extensions/src/cache.d.ts +6 -4
- package/dist-extensions/src/cache.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cache.spec.ts +74 -0
- package/src/cache.ts +20 -18
- package/src/shapes/Text/Text.ts +9 -9
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
|
-
|
|
366
|
-
|
|
367
|
+
const cache = this.charWidthsCache;
|
|
368
|
+
if (!cache.has(fontFamily)) {
|
|
369
|
+
cache.set(fontFamily, new Map());
|
|
367
370
|
}
|
|
368
|
-
const fontCache =
|
|
371
|
+
const fontCache = cache.get(fontFamily);
|
|
369
372
|
const cacheKey = "".concat(fontStyle.toLowerCase(), "_").concat((fontWeight + '').toLowerCase());
|
|
370
|
-
if (!fontCache
|
|
371
|
-
fontCache
|
|
373
|
+
if (!fontCache.has(cacheKey)) {
|
|
374
|
+
fontCache.set(cacheKey, new Map());
|
|
372
375
|
}
|
|
373
|
-
return fontCache
|
|
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
|
|
392
|
-
|
|
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.
|
|
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
|
|
19383
|
-
previousWidth = fontCache
|
|
19384
|
+
if (previousChar && fontCache.has(previousChar)) {
|
|
19385
|
+
previousWidth = fontCache.get(previousChar);
|
|
19384
19386
|
}
|
|
19385
|
-
if (fontCache
|
|
19386
|
-
kernedWidth = width = fontCache
|
|
19387
|
+
if (fontCache.has(_char)) {
|
|
19388
|
+
kernedWidth = width = fontCache.get(_char);
|
|
19387
19389
|
}
|
|
19388
|
-
if (stylesAreEqual && fontCache
|
|
19389
|
-
coupleWidth = fontCache
|
|
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
|
|
19400
|
+
fontCache.set(_char, width);
|
|
19399
19401
|
}
|
|
19400
19402
|
if (previousWidth === undefined && stylesAreEqual && previousChar) {
|
|
19401
19403
|
previousWidth = ctx.measureText(previousChar).width;
|
|
19402
|
-
fontCache
|
|
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
|
|
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
|
}
|