Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(render): skip invalid shape stroke widths (#7370)
Univer5fcf1654852c
diff --git a/packages/engine-render/src/shape/__tests__/basic-shapes-extra.spec.ts b/packages/engine-render/src/shape/__tests__/basic-shapes-extra.spec.tsindex eae1062cf1..164119cacb 100644--- a/packages/engine-render/src/shape/__tests__/basic-shapes-extra.spec.ts+++ b/packages/engine-render/src/shape/__tests__/basic-shapes-extra.spec.ts@@ -141,6 +141,23 @@ describe('basic shape and position helpers', () => {expect(ctx.restore).toHaveBeenCalled();});+ it('skips non-positive and non-finite stroke widths', () => {+ for (const strokeWidth of [0, -1, Number.NaN, Number.POSITIVE_INFINITY]) {+ const ctx = createShapeCtx();++ Rect.drawWith(ctx, {+ width: 80,+ height: 32,+ fill: '#ffffff',+ stroke: '#ff0000',+ strokeWidth,+ });++ expect(ctx.fill).toHaveBeenCalled();+ expect(ctx.stroke).not.toHaveBeenCalled();+ }+ });+it('draws a rounded visual rect centered in the interaction bounds', () => {const rect = new Rect('rect-visual', {width: 80,diff --git a/packages/engine-render/src/shape/shape.ts b/packages/engine-render/src/shape/shape.tsindex ca5d7aeb2b..751ebdeb79 100644--- a/packages/engine-render/src/shape/shape.ts+++ b/packages/engine-render/src/shape/shape.ts@@ -283,7 +283,7 @@ export abstract class Shape<T extends IShapeProps> extends BaseObject {// let { scaleX, scaleY } = props;// const { scaleX = 1, scaleY = 1 } = ctx.getScale();- if (!stroke || strokeWidth === 0) {+ if (!stroke || strokeWidth === undefined || !Number.isFinite(strokeWidth) || strokeWidth <= 0) {return;}