tokenizeMessage: ignore commas and dots that end a url

This commit is contained in:
Liam Fitzgerald 2021-06-11 09:43:39 +10:00
parent 001ff8becc
commit 93c968d9fa
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
2 changed files with 14 additions and 1 deletions

View File

@ -1,7 +1,7 @@
import urbitOb from 'urbit-ob';
import { parsePermalink, permalinkToReference } from '~/logic/lib/permalinks';
const URL_REGEX = new RegExp(String(/^([^[\]]*?)(([\w\-\+]+:\/\/)[-a-zA-Z0-9:@;?&=\/%\+\.\*!'\(\),\$_\{\}\^~\[\]`#|]+)([\s\S]*)/.source));
const URL_REGEX = new RegExp(String(/^([^[\]]*?)(([\w\-\+]+:\/\/)[-a-zA-Z0-9:@;?&=\/%\+\.\*!'\(\),\$_\{\}\^~\[\]`#|]+[-a-zA-Z0-9:@;?&=\/%\+\*!'\(\)\$_\{\}\^~\[\]`#|])([\s\S]*)/.source));
const PATP_REGEX = /^([\s\S]*?)(~[a-z_-]+)([\s\S]*)/;

View File

@ -100,4 +100,17 @@ describe('tokenizeMessage', () => {
expect(text).toBe('test ');
expect(url).toBe('https://en.wikipedia.org/wiki/Turbo_(gastropod)');
});
it('should ignore ending commas', () => {
const example = 'https://tlon.io/test, foo';
const [{ url }, { text }] = tokenizeMessage(example);
expect(text).toBe(', foo');
expect(url).toBe('https://tlon.io/test');
});
it('should ignore ending dots', () => {
const example = 'https://tlon.io/test. foo';
const [{ url }, { text }] = tokenizeMessage(example);
expect(text).toBe('. foo');
expect(url).toBe('https://tlon.io/test');
});
});