From 2e025d10cf4d5f1cd6e7a3d13ec994f529c9dd11 Mon Sep 17 00:00:00 2001 From: Yanlong Wang Date: Sun, 5 May 2024 16:29:39 +0800 Subject: [PATCH] fix: the complex regexp caused node.js process to hang Co-authored-by: Claude 3 opus --- backend/functions/src/index.ts | 4 ---- backend/functions/src/utils/markdown.ts | 4 ++-- thinapps-shared | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/backend/functions/src/index.ts b/backend/functions/src/index.ts index d251b34..a6016bb 100644 --- a/backend/functions/src/index.ts +++ b/backend/functions/src/index.ts @@ -27,7 +27,3 @@ process.on('uncaughtException', (err) => { console.error('Uncaught exception, process quit.'); throw err; }); - -if (!process.env.FUNCTIONS_EMULATOR) { - registry.walk_around_firebase_stall = true; -} diff --git a/backend/functions/src/utils/markdown.ts b/backend/functions/src/utils/markdown.ts index 73dfa39..f8def89 100644 --- a/backend/functions/src/utils/markdown.ts +++ b/backend/functions/src/utils/markdown.ts @@ -2,14 +2,14 @@ export function tidyMarkdown(markdown: string): string { // Step 1: Handle complex broken links with text and optional images spread across multiple lines - let normalizedMarkdown = markdown.replace(/\[\s*([^]+?)\s*\]\s*\(\s*([^)]+)\s*\)/g, (match, text, url) => { + let normalizedMarkdown = markdown.replace(/\[\s*([^\]\n]+?)\s*\]\s*\(\s*([^)]+)\s*\)/g, (match, text, url) => { // Remove internal new lines and excessive spaces within the text text = text.replace(/\s+/g, ' ').trim(); url = url.replace(/\s+/g, '').trim(); return `[${text}](${url})`; }); - normalizedMarkdown = normalizedMarkdown.replace(/\[\s*([^!]*?)\s*\n*(?:!\[([^\]]*)\]\((.*?)\))?\s*\n*\]\s*\(\s*([^)]+)\s*\)/g, (match, text, alt, imgUrl, linkUrl) => { + normalizedMarkdown = normalizedMarkdown.replace(/\[\s*([^\]\n!]*?)\s*\n*(?:!\[([^\]]*)\]\((.*?)\))?\s*\n*\]\s*\(\s*([^)]+)\s*\)/g, (match, text, alt, imgUrl, linkUrl) => { // Normalize by removing excessive spaces and new lines text = text.replace(/\s+/g, ' ').trim(); alt = alt ? alt.replace(/\s+/g, ' ').trim() : ''; diff --git a/thinapps-shared b/thinapps-shared index 21e6ece..d3bb3a7 160000 --- a/thinapps-shared +++ b/thinapps-shared @@ -1 +1 @@ -Subproject commit 21e6ece0f378fe26db888bc5ff7715a43bf022bd +Subproject commit d3bb3a7335ec9d96c68d1edf1b66fdf5e2fe5b7c