Skip to content

Commit

Permalink
Merge pull request intuit#2464 from LittleGreenYoda42/test/fix-slack-…
Browse files Browse the repository at this point in the history
…long-line-handling

fix: handling of long strings in slack plugin
  • Loading branch information
hipstersmoothie authored Jun 28, 2024
2 parents 335fadb + cbd3424 commit 0509a79
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions plugins/slack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,17 @@ interface Block {
const CHANGELOG_LINE = /^\s*•/;
type Messages = [Block[], ...Array<Block[] | FileUpload>];

/** 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;
Expand Down

0 comments on commit 0509a79

Please sign in to comment.