mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Fix matching multiple whitespace characters at the end of a string
This commit is contained in:
parent
69a9534463
commit
80fcda2b01
2 changed files with 2 additions and 2 deletions
|
|
@ -145,7 +145,7 @@ Deno.test('removeTrailingTokens with newlines', () => {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const result = removeTrailingTokens(
|
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,
|
urls,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ export function removeTrailingTokens(text: string, tokens: Set<string>): string
|
||||||
let trimmedText = text;
|
let trimmedText = text;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const match = trimmedText.match(/\s?([^\s]+)\s?$/);
|
const match = trimmedText.match(/([^\s]+)(?:\s+)?$/);
|
||||||
if (match && tokens.has(match[1])) {
|
if (match && tokens.has(match[1])) {
|
||||||
trimmedText = trimmedText.slice(0, match.index).replace(/\s+$/, '');
|
trimmedText = trimmedText.slice(0, match.index).replace(/\s+$/, '');
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue