瀏覽代碼

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
Axel Viala 6 年之前
父節點
當前提交
b51d98d6d1
共有 3 個文件被更改,包括 36 次插入3 次删除
  1. 1 0
      CHANGES.md
  2. 34 0
      spec/messages.js
  3. 1 3
      src/headless/converse-muc.js

+ 1 - 0
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

+ 34 - 0
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'], {},

+ 1 - 3
src/headless/converse-muc.js

@@ -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) {