From 80fcda2b018a07b562132abc5bc1bf8cda6f8c3a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 12 Mar 2025 16:53:22 -0500 Subject: [PATCH] Fix matching multiple whitespace characters at the end of a string --- packages/ditto/utils/note.test.ts | 2 +- packages/ditto/utils/note.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ditto/utils/note.test.ts b/packages/ditto/utils/note.test.ts index 69e5bdbb..2cfe5f16 100644 --- a/packages/ditto/utils/note.test.ts +++ b/packages/ditto/utils/note.test.ts @@ -145,7 +145,7 @@ Deno.test('removeTrailingTokens with newlines', () => { ]); const result = removeTrailingTokens( - 'Hey!\n\nthis is cool \n\nhttps://ditto.pub/a.png\nhttps://ditto.pub/b.jpg', + 'Hey!\n\nthis is cool \n\nhttps://ditto.pub/a.png\nhttps://ditto.pub/b.jpg\n ', urls, ); diff --git a/packages/ditto/utils/note.ts b/packages/ditto/utils/note.ts index 9fe9439b..7b1405ff 100644 --- a/packages/ditto/utils/note.ts +++ b/packages/ditto/utils/note.ts @@ -74,7 +74,7 @@ export function removeTrailingTokens(text: string, tokens: Set): string let trimmedText = text; while (true) { - const match = trimmedText.match(/\s?([^\s]+)\s?$/); + const match = trimmedText.match(/([^\s]+)(?:\s+)?$/); if (match && tokens.has(match[1])) { trimmedText = trimmedText.slice(0, match.index).replace(/\s+$/, ''); } else {