From b51d98d6d1d97df6f87143f82210380a5b192ee8 Mon Sep 17 00:00:00 2001 From: Axel Viala Date: Mon, 4 Mar 2019 20:47:06 +0100 Subject: [PATCH] Fix #1327: Refusing url and email as mentions Before the function `extractReference` in `/src/headless/converse-muc.js` matched url and email. Fix: https://github.com/conversejs/converse.js/issues/1327 --- CHANGES.md | 1 + spec/messages.js | 34 ++++++++++++++++++++++++++++++++++ src/headless/converse-muc.js | 4 +--- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 44b766e0b..b1fa97232 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/spec/messages.js b/spec/messages.js index b902c9761..10c1b4334 100644 --- a/spec/messages.js +++ b/spec/messages.js @@ -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'], {}, diff --git a/src/headless/converse-muc.js b/src/headless/converse-muc.js index a55b909dc..cbc327179 100644 --- a/src/headless/converse-muc.js +++ b/src/headless/converse-muc.js @@ -369,9 +369,7 @@ converse.plugins.add('converse-muc', { extractReference (text, index) { for (let i=index; i