Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE-5969 Do not crash if style is null when checking if is empty #5971

Merged
merged 1 commit into from
Nov 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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