Alex-D / Trumbowyg

A lightweight and amazing WYSIWYG JavaScript editor under 10kB
https://alex-d.github.io/Trumbowyg
MIT License
4k stars 614 forks source link

Infinite loop while selecting text inside table cell #1443

Open vmorreel opened 7 months ago

vmorreel commented 7 months ago

Bug case

When selecting text inside table cells, then the selection propagates to the cell, then the browser tab completely freeze.

It happens only when :

My template row is as follow :

<td class="border-left" colspan="{{^mustache_condition}}2{{/mustache_condition}}">My cell content</td>

The bug come from the while loop at line 533 of trumbowyg.table.min.js :

while (tableState[rowIndex][columnIndex] !== undefined) {
    columnIndex += 1;
}

So, in my case my colspan attribute is NaN value {{^mustache_condition}}2{{/mustache_condition}}.

Checking if !isNaN(colspanAttr) in ternary line 530 of trumbowyg.table.min.js resolves the issue. (supposed same behavior with rowspanattribute)

Maybe add scope on selection only on table inside a trumbowyg element could be a nicer solution?

Description

Context:

How to reproduce?

Here's a fiddle to reproduce the error : https://jsfiddle.net/wqk2xLjr/10/