A platform for community discussion. Free, open, simple.
FIX: Handle empty table bodies in rich editor paste (#37603)
Renato Atilio5bfc9764f724
diff --git a/frontend/discourse/app/static/prosemirror/extensions/table.js b/frontend/discourse/app/static/prosemirror/extensions/table.jsindex 280136ab1cd..cfb23b75a29 100644--- a/frontend/discourse/app/static/prosemirror/extensions/table.js+++ b/frontend/discourse/app/static/prosemirror/extensions/table.js@@ -246,6 +246,10 @@ const extension = {const maxColumns = findMaxColumns(tbody);const firstRow = tbody.firstChild;+ if (!firstRow || maxColumns === 0) {+ return tableNode;+ }+const header = schema.nodes.table_head.create({},createHeaderRow(firstRow, maxColumns, schema)diff --git a/spec/system/composer/prosemirror_pasting_spec.rb b/spec/system/composer/prosemirror_pasting_spec.rbindex e1efa08afa8..093fd64b86a 100644--- a/spec/system/composer/prosemirror_pasting_spec.rb+++ b/spec/system/composer/prosemirror_pasting_spec.rb@@ -341,5 +341,25 @@ describe "Composer - ProseMirror - Pasting content", type: :system doexpect(composer).to have_value(markdown)end++ it "handles tables with empty rows without crashing" do+ cdp.allow_clipboard+ open_composer++ html = <<~HTML+ <table>+ <tbody>+ <tr></tr>+ </tbody>+ </table>+ <p>After table</p>+ HTML++ cdp.copy_paste(html, html: true)++ composer.toggle_rich_editor++ expect(composer).to have_value("| |\n|----|\n\nAfter table")+ endendend