Skip to content

Commit 0509a79

Browse files
Merge pull request #2464 from LittleGreenYoda42/test/fix-slack-long-line-handling
fix: handling of long strings in slack plugin
2 parents 335fadb + cbd3424 commit 0509a79

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)