mirror of
https://github.com/ilyakooo0/urbit.git
synced 2025-01-04 13:19:48 +03:00
tokenizeMessage: less greedy
This commit is contained in:
parent
3d9036b10f
commit
623da874e5
@ -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}`;
|
||||
|
||||
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user