From cbd342445d12952dcd11becd19cb9ad799835fd4 Mon Sep 17 00:00:00 2001 From: Martin Elias Date: Wed, 26 Jun 2024 13:00:47 +0200 Subject: [PATCH] fix: handling of long strings in slack --- plugins/slack/src/index.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/slack/src/index.ts b/plugins/slack/src/index.ts index 5d41d2240..907426961 100644 --- a/plugins/slack/src/index.ts +++ b/plugins/slack/src/index.ts @@ -91,16 +91,17 @@ interface Block { const CHANGELOG_LINE = /^\s*•/; type Messages = [Block[], ...Array]; -/** Split a long spring into chunks by character limit */ +/** Split a long string into chunks by character limit */ const splitCharacterLimitAtNewline = (line: string, charLimit: number) => { const splitLines = []; let buffer = line; while (buffer) { // get the \n closest to the char limit - const newlineIndex = buffer.lastIndexOf("\n", charLimit) || charLimit; - splitLines.push(buffer.slice(0, newlineIndex)); - buffer = buffer.slice(newlineIndex); + const newlineIndex = buffer.indexOf("\n", charLimit); + const endOfLine = newlineIndex >= 0 ? newlineIndex : charLimit; + splitLines.push(buffer.slice(0, endOfLine)); + buffer = buffer.slice(endOfLine); } return splitLines;