Fix infinite recursion in markdown parsing

🐛 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
This commit is contained in:
2025-08-29 23:22:06 +02:00
parent dc70b74f7d
commit 526c265e52

View File

@@ -302,7 +302,8 @@ class Insertr {
// Check for headings // Check for headings
if (line.match(/^#{1,6}\s/)) { if (line.match(/^#{1,6}\s/)) {
if (currentBlock) blocks.push(currentBlock); if (currentBlock) blocks.push(currentBlock);
const level = line.match(/^#+/)[0].length; const hashMatch = line.match(/^#+/);
const level = hashMatch ? hashMatch[0].length : 1;
currentBlock = { currentBlock = {
type: `h${level}`, type: `h${level}`,
content: line.replace(/^#+\s*/, '').trim() content: line.replace(/^#+\s*/, '').trim()