From 526c265e5247cc934128816daa6d9d8957160dd1 Mon Sep 17 00:00:00 2001 From: Joakim Date: Fri, 29 Aug 2025 23:22:06 +0200 Subject: [PATCH] Fix infinite recursion in markdown parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 Critical Fix: Maximum call stack exceeded error ✅ Solution: Properly handle regex match result in parseMarkdownToBlocks() 🔧 Issue: - line.match(/^#+/)[0].length caused infinite recursion - Browser crashed when editing rich content with headings 🔧 Fix: - Store regex match result in variable first - Add null check before accessing match result - Prevents stack overflow when parsing markdown headings ⚡ Now safe to edit content with # headings without crashes --- demo-site/insertr/insertr.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/demo-site/insertr/insertr.js b/demo-site/insertr/insertr.js index 6da8a14..e6fdb16 100644 --- a/demo-site/insertr/insertr.js +++ b/demo-site/insertr/insertr.js @@ -302,7 +302,8 @@ class Insertr { // Check for headings if (line.match(/^#{1,6}\s/)) { if (currentBlock) blocks.push(currentBlock); - const level = line.match(/^#+/)[0].length; + const hashMatch = line.match(/^#+/); + const level = hashMatch ? hashMatch[0].length : 1; currentBlock = { type: `h${level}`, content: line.replace(/^#+\s*/, '').trim()