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
This commit is contained in:
Axel Viala 2019-03-04 20:47:06 +01:00 committed by JC Brand
parent 33600eeece
commit b51d98d6d1
3 changed files with 36 additions and 3 deletions

View File

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

View File

@ -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'], {},

View File

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