tokenizeMessage: less greedy

This commit is contained in:
Liam Fitzgerald 2021-05-28 10:47:51 +10:00
parent 3d9036b10f
commit 623da874e5
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
2 changed files with 15 additions and 2 deletions

View File

@ -3,9 +3,9 @@ import { parsePermalink, permalinkToReference } from '~/logic/lib/permalinks';
const URL_REGEX = new RegExp(String(/^([^[\]]*?)(([\w\-\+]+:\/\/)[-a-zA-Z0-9:@;?&=\/%\+\.\*!'\(\),\$_\{\}\^~\[\]`#|]+[\w/])([\s\S]*)/.source));
const PATP_REGEX = /^([\s\S]*)(~[a-z_-]+)([\s\S]*)/;
const PATP_REGEX = /^([\s\S]*?)(~[a-z_-]+)([\s\S]*)/;
const GROUP_REGEX = new RegExp(String(/^([\s\S ]*)(~[-a-z_]+\/[-a-z]+)([\s\S]*)/.source));
const GROUP_REGEX = new RegExp(String(/^([\s\S ]*?)(~[-a-z_]+\/[-a-z]+)([\s\S]*)/.source));
const convertToGroupRef = group => `web+urbitgraph://group/${group}`;

View File

@ -80,4 +80,17 @@ describe('tokenizeMessage', () => {
expect(url).toEqual('https://urbit.org');
expect(text2).toEqual(' lately?');
});
it('should tokenize two links and a mention', () => {
const example = '~haddef-sigwen, test https://tlon.io test https://urbit.org test ~hastuc-dibtux';
const result = tokenizeMessage(example);
const [{ mention }, { text: one }, { url: tlon }, { text: two }, { url: urbit }, { text: three }, { mention: hastuc }] = result;
expect(mention).toEqual('~haddef-sigwen');
expect(one).toEqual(', test ');
expect(tlon).toEqual('https://tlon.io');
expect(two).toEqual(' test ');
expect(urbit).toEqual('https://urbit.org');
expect(three).toEqual(' test ');
expect(hastuc).toEqual('~hastuc-dibtux');
});
});