From ce32a3240e1a845c6082382540c9592dfd12be5b Mon Sep 17 00:00:00 2001 From: gloryyin Date: Sat, 10 Sep 2022 14:44:33 +0800 Subject: [PATCH] fix: fix parsing rgba error --- src/Shape.ts | 7 +++++-- test/unit/Shape-test.ts | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Shape.ts b/src/Shape.ts index 95da9a54..c5e4c551 100644 --- a/src/Shape.ts +++ b/src/Shape.ts @@ -324,8 +324,11 @@ export class Shape< return this._getCache(SHADOW_RGBA, this._getShadowRGBA); } _getShadowRGBA() { - if (this.hasShadow()) { - var rgba = Util.colorToRGBA(this.shadowColor()); + if (!this.hasShadow()) { + return; + } + var rgba = Util.colorToRGBA(this.shadowColor()); + if (rgba) { return ( 'rgba(' + rgba.r + diff --git a/test/unit/Shape-test.ts b/test/unit/Shape-test.ts index 2e616c18..421a2476 100644 --- a/test/unit/Shape-test.ts +++ b/test/unit/Shape-test.ts @@ -1229,6 +1229,11 @@ describe('Shape', function () { // reset shadow circle.shadowColor(null); assert.equal(circle.getShadowRGBA(), undefined); + + // illegal color + circle.shadowColor('#0000f'); + assert.equal(circle.hasShadow(), true); + assert.equal(circle.getShadowRGBA(), undefined); }); it('scale should also effect shadow offset', function () {