Skip to content

Commit b51d98d

Browse files
darnuriajcbrand
authored andcommitted
Fix #1327: Refusing url and email as mentions
Before the function `extractReference` in `/src/headless/converse-muc.js` matched url and email. Fix: #1327
1 parent 33600ee commit b51d98d

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

‎CHANGES.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- New config setting [show_client_info](https://conversejs.org/docs/html/configuration.html#show-client-info)
1212
- #1149: With `xhr_user_search_url`, contact requests are not being sent out
1313
- #1213: Switch roster filter input and icons
14+
- #1327: fix False mentions positives in URLs and Email addresses
1415
- #1373: Re-add support for the [muc_domain](https://conversejs.org/docs/html/configuration.html#muc-domain) setting
1516
- #1400: When a chat message is just an emoji, enlarge the emoji
1617
- #1437: List of groupchats in modal doesn't scroll

‎spec/messages.js‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,6 +2742,40 @@
27422742
done();
27432743
}));
27442744

2745+
it("parses for mentions as indicated with an @ preceded by a space or at the start of the text",
2746+
mock.initConverse(
2747+
null, ['rosterGroupsFetched'], {},
2748+
async function (done, _converse) {
2749+
2750+
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'tom');
2751+
const view = _converse.api.chatviews.get('lounge@localhost');
2752+
['NotAnAdress', 'darnuria'].forEach((nick) => {
2753+
_converse.connection._dataRecv(test_utils.createRequest(
2754+
$pres({
2755+
'to': 'tom@localhost/resource',
2756+
'from': `lounge@localhost/${nick}`
2757+
})
2758+
.c('x', {xmlns: Strophe.NS.MUC_USER})
2759+
.c('item', {
2760+
'affiliation': 'none',
2761+
'jid': `${nick.replace(/\s/g, '-')}@localhost/resource`,
2762+
'role': 'participant'
2763+
})));
2764+
});
2765+
2766+
// Test that we don't match @nick in email adresses.
2767+
let [text, references] = view.model.parseTextForReferences('contact contact@NotAnAdress.eu');
2768+
expect(references.length).toBe(0);
2769+
expect(text).toBe('contact contact@NotAnAdress.eu');
2770+
2771+
// Test that we don't match @nick in url
2772+
[text, references] = view.model.parseTextForReferences('nice website https://darnuria.eu/@darnuria');
2773+
expect(references.length).toBe(0);
2774+
expect(text).toBe('nice website https://darnuria.eu/@darnuria');
2775+
2776+
done();
2777+
}));
2778+
27452779
it("can get corrected and given new references",
27462780
mock.initConverse(
27472781
null, ['rosterGroupsFetched'], {},

‎src/headless/converse-muc.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,7 @@ converse.plugins.add('converse-muc', {
369369

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

0 commit comments

Comments
 (0)