Skip to content

Commit cbd3424

Browse files
fix: handling of long strings in slack
1 parent 335fadb commit cbd3424

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

plugins/slack/src/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,17 @@ interface Block {
9191
const CHANGELOG_LINE = /^\s*/;
9292
type Messages = [Block[], ...Array<Block[] | FileUpload>];
9393

94-
/** Split a long spring into chunks by character limit */
94+
/** Split a long string into chunks by character limit */
9595
const splitCharacterLimitAtNewline = (line: string, charLimit: number) => {
9696
const splitLines = [];
9797
let buffer = line;
9898

9999
while (buffer) {
100100
// get the \n closest to the char limit
101-
const newlineIndex = buffer.lastIndexOf("\n", charLimit) || charLimit;
102-
splitLines.push(buffer.slice(0, newlineIndex));
103-
buffer = buffer.slice(newlineIndex);
101+
const newlineIndex = buffer.indexOf("\n", charLimit);
102+
const endOfLine = newlineIndex >= 0 ? newlineIndex : charLimit;
103+
splitLines.push(buffer.slice(0, endOfLine));
104+
buffer = buffer.slice(endOfLine);
104105
}
105106

106107
return splitLines;

0 commit comments

Comments
 (0)