Skip to content

Commit

Permalink
Tweak to object._setLineDash to avoid cycles when nothing in array (e…
Browse files Browse the repository at this point in the history
…mpty array truthy) (fabricjs#6000)
  • Loading branch information
BradleyHill authored and Hristo Chakarov committed Jul 27, 2021
1 parent 6764a0f commit 62b182d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@
* @param {Function} alternative function to call if browser does not support lineDash
*/
_setLineDash: function(ctx, dashArray, alternative) {
if (!dashArray) {
if (!dashArray || dashArray.length === 0) {
return;
}
// Spec requires the concatenation of two copies the dash list when the number of elements is odd
Expand Down
4 changes: 4 additions & 0 deletions test/unit/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,10 @@
assert.equal(object.strokeDashArray.length, 3, 'strokeDash array is odd');
object._setLineDash(canvas.contextContainer, object.strokeDashArray, null);
assert.equal(object.strokeDashArray.length, 6, 'strokeDash array now is even');

assert.equal(canvas.contextContainer.getLineDash().length, 6, 'object pushed line dash to canvas');
object._setLineDash(canvas.contextContainer, [], null);
assert.equal(canvas.contextContainer.getLineDash().length, 6, 'bailed immediately as array empty');
});

QUnit.test('straighten', function(assert) {
Expand Down

0 comments on commit 62b182d

Please sign in to comment.