Skip to content

Commit

Permalink
ISSUE-5969 Do not crash if style is null when checking if is empty (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored and Hristo Chakarov committed Jul 27, 2021
1 parent 180d730 commit aa77d4e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/shapes/textbox.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@
* @return {Boolean}
*/
isEmptyStyles: function(lineIndex) {
var offset = 0, nextLineIndex = lineIndex + 1, nextOffset, obj, shouldLimit = false;
var map = this._styleMap[lineIndex];
var mapNextLine = this._styleMap[lineIndex + 1];
if (!this.styles) {
return true;
}
var offset = 0, nextLineIndex = lineIndex + 1, nextOffset, obj, shouldLimit = false,
map = this._styleMap[lineIndex], mapNextLine = this._styleMap[lineIndex + 1];
if (map) {
lineIndex = map.line;
offset = map.offset;
Expand Down
8 changes: 8 additions & 0 deletions test/unit/textbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@
assert.equal(textbox.isEmptyStyles(1), true, 'style is empty at line 1');
});

QUnit.test('isEmptyStyles does not crash on null styles', function(assert) {
var textbox = new fabric.Textbox('x x', { width: 5 });
textbox.styles = null;
assert.equal(textbox._textLines.length, 2, 'lines are wrapped');
assert.equal(textbox._unwrappedTextLines.length, 1, 'there is only one text line');
assert.equal(textbox.isEmptyStyles(1), true, 'style is empty');
});

QUnit.test('isEmptyStyles alternate lines', function(assert) {
var textbox = new fabric.Textbox('xa xb xc xd xe\nya yb', {
width: 5,
Expand Down

0 comments on commit aa77d4e

Please sign in to comment.