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:
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user