From df1a772dfb558f1d0973eaaf0df37a71bba7d427 Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Mon, 8 Jul 2024 15:48:21 +0200 Subject: [PATCH] Fix regex escaping --- code/core/src/core-server/utils/save-story/save-story.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/core/src/core-server/utils/save-story/save-story.ts b/code/core/src/core-server/utils/save-story/save-story.ts index 9d4c9df841b9..8ad7ef738ff3 100644 --- a/code/core/src/core-server/utils/save-story/save-story.ts +++ b/code/core/src/core-server/utils/save-story/save-story.ts @@ -35,8 +35,8 @@ const parseArgs = (args: string): Record => // Removes extra newlines between story properties. See https://github.com/benjamn/recast/issues/242 // Only updates the part of the code for the story with the given name. const removeExtraNewlines = (code: string, name: string) => { - const anything = '(.|\r\n|\r|\n)'; // Multiline match for any character. - const newline = '(\r\n|\r|\n)'; // Either newlines or carriage returns may be used in the file. + const anything = '([\\s\\S])'; // Multiline match for any character. + const newline = '(\\r\\n|\\r|\\n)'; // Either newlines or carriage returns may be used in the file. const closing = newline + '};' + newline; // Marks the end of the story definition. const regex = new RegExp( // Looks for an export by the given name, considers the first closing brace on its own line