Skip to content
Permalink
Browse files

Fix #1327: Refusing url and email as mentions

Before the function `extractReference` in
`/src/headless/converse-muc.js` matched url and email.

Fix: #1327
  • Loading branch information...
darnuria authored and jcbrand committed Mar 4, 2019
1 parent 33600ee commit b51d98d6d1d97df6f87143f82210380a5b192ee8
Showing with 36 additions and 3 deletions.
  1. +1 −0 CHANGES.md
  2. +34 −0 spec/messages.js
  3. +1 −3 src/headless/converse-muc.js
@@ -11,6 +11,7 @@
- New config setting [show_client_info](https://conversejs.org/docs/html/configuration.html#show-client-info)
- #1149: With `xhr_user_search_url`, contact requests are not being sent out
- #1213: Switch roster filter input and icons
- #1327: fix False mentions positives in URLs and Email addresses
- #1373: Re-add support for the [muc_domain](https://conversejs.org/docs/html/configuration.html#muc-domain) setting
- #1400: When a chat message is just an emoji, enlarge the emoji
- #1437: List of groupchats in modal doesn't scroll
@@ -2742,6 +2742,40 @@
done();
}));

it("parses for mentions as indicated with an @ preceded by a space or at the start of the text",
mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {

await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'tom');
const view = _converse.api.chatviews.get('lounge@localhost');
['NotAnAdress', 'darnuria'].forEach((nick) => {
_converse.connection._dataRecv(test_utils.createRequest(
$pres({
'to': 'tom@localhost/resource',
'from': `lounge@localhost/${nick}`
})
.c('x', {xmlns: Strophe.NS.MUC_USER})
.c('item', {
'affiliation': 'none',
'jid': `${nick.replace(/\s/g, '-')}@localhost/resource`,
'role': 'participant'
})));
});

// Test that we don't match @nick in email adresses.
let [text, references] = view.model.parseTextForReferences('contact contact@NotAnAdress.eu');
expect(references.length).toBe(0);
expect(text).toBe('contact contact@NotAnAdress.eu');

// Test that we don't match @nick in url
[text, references] = view.model.parseTextForReferences('nice website https://darnuria.eu/@darnuria');
expect(references.length).toBe(0);
expect(text).toBe('nice website https://darnuria.eu/@darnuria');

done();
}));

it("can get corrected and given new references",
mock.initConverse(
null, ['rosterGroupsFetched'], {},
@@ -369,9 +369,7 @@ converse.plugins.add('converse-muc', {

extractReference (text, index) {
for (let i=index; i<text.length; i++) {
if (text[i] !== '@') {
continue
} else {
if (text[i] === '@' && (i === 0 || text[i - 1] === ' ')) {
const match = text.slice(i+1),
ref = this.getReferenceForMention(match, i);
if (ref) {

0 comments on commit b51d98d

Please sign in to comment.
You can’t perform that action at this time.