fix(render): skip invalid shape stroke widths (#7370)

This commit is contained in:
Univer
2026-07-29 21:39:11 +08:00
committed by GitHub
parent a5851c95b2
commit 5fcf165485
2 changed files with 18 additions and 1 deletions
@@ -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,
+1 -1
View File
@@ -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;
}