From 4a30b6aa02e393370499799072882f3d0d32f9fa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mehmet=20=C3=87al=C4=B1=C5=9Fkan?=
<49614175+caliskanmehmet@users.noreply.github.com>
Date: Mon, 25 Nov 2024 20:01:12 +0300
Subject: [PATCH 1/2] Fixes #473 by reducing the backtracking to handle the
long strings of spaces
---
index.compiler.spec.tsx | 22 ++++++++++++++++++++++
index.tsx | 2 +-
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/index.compiler.spec.tsx b/index.compiler.spec.tsx
index db07f0bf..15141dd9 100644
--- a/index.compiler.spec.tsx
+++ b/index.compiler.spec.tsx
@@ -4824,3 +4824,25 @@ it('#597 handles script tag with empty content', () => {
`)
})
+
+it('#473 handles content with multiple empty spaces without crashing', () => {
+ render(
+ compiler(
+ '##Long \r\n \r\n ###input \ntest'
+ )
+ )
+
+ expect(root.innerHTML).toMatchInlineSnapshot(`
+
+
+ Long
+
+
+
+ test
+
+
+ `)
+})
\ No newline at end of file
diff --git a/index.tsx b/index.tsx
index 185651b0..2d0c4a02 100644
--- a/index.tsx
+++ b/index.tsx
@@ -185,7 +185,7 @@ const BREAK_LINE_R = /^ {2,}\n/
const BREAK_THEMATIC_R = /^(?:( *[-*_])){3,} *(?:\n *)+\n/
const CODE_BLOCK_FENCED_R =
/^(?: {1,3})?(`{3,}|~{3,}) *(\S+)? *([^\n]*?)?\n([\s\S]*?)(?:\1\n?|$)/
-const CODE_BLOCK_R = /^(?: {4}[^\n]+\n*)+(?:\n *)+\n?/
+const CODE_BLOCK_R = /^(?: {4}[^\n]+\n*)+(?:\n *)*\n?/
const CODE_INLINE_R = /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/
const CONSECUTIVE_NEWLINE_R = /^(?:\n *)*\n/
const CR_NEWLINE_R = /\r\n?/g
From 76bbc4ad8c47daff8aaae59c99a6e57b03097fd3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mehmet=20=C3=87al=C4=B1=C5=9Fkan?=
<49614175+caliskanmehmet@users.noreply.github.com>
Date: Mon, 25 Nov 2024 21:19:10 +0300
Subject: [PATCH 2/2] Improved the test case to reproduce the problem
---
index.compiler.spec.tsx | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/index.compiler.spec.tsx b/index.compiler.spec.tsx
index 15141dd9..2854b803 100644
--- a/index.compiler.spec.tsx
+++ b/index.compiler.spec.tsx
@@ -4828,20 +4828,21 @@ it('#597 handles script tag with empty content', () => {
it('#473 handles content with multiple empty spaces without crashing', () => {
render(
compiler(
- '##Long \r\n \r\n ###input \ntest'
+ 'Test \r\n \r\n Test'
)
)
expect(root.innerHTML).toMatchInlineSnapshot(`
-
- Long
-
-
- test
+ Test
+
+
+
+
+
+
+ Test
`)