Group mentions that begin with the same characters may be incorrect


(Robert) #1

Hey everyone,

I have teams like: @ORGANISATION and @ORGANISATION-Board. I have the impressions that both groups will be mentioned if the second one in part of the text. I just mentioned a very small group in my production forum and many users got a group_mention notification and I cannot imagine another reason for that.


No Highlighting of Group mentions in Markdown Preview
(cpradio) #2

Okay, just want to get the repo steps clearer, as I’m a bit confused.

So group ORGANISATION has Members A, B, C, D, E, F, G, H, I?

Group ORGANISATION-BOARD has Members F, G, H, I?

Mentioning ORGANISATION-BOARD is notifying A, B, C, D, E, F, G, H, and I? and not just F, G, H, I?


(cpradio) #3

Just confirmed my suspicion.

Repro Steps that I used:

  1. As an Admin Create Two Groups, Special and Special-Force
  2. Add Members testuser1, testuser2, testuser3 to Special
  3. Add Members testuser1 to Special-Force
  4. Mention @Special-Force in a new Topic/Post
  5. Login as testuser3, mention notification was sent to testuser3 :frowning:
  6. Login as testuser2, mention notification was sent to testuser2 :frowning:
  7. Login as testuser1, mention notification was sent to testuser1 :smile:

(Jeff Atwood) #4

So basically groups that begin with the same string may notify the incorrect group that matches the beginning of the string? @sam


(Robert) #5

Exactly! Sorry for beeing a bit unclear. No one should be able to mention @ORGANISATION in my forum and now there is an easy way to spam many people. I hope that the necessary fix is obvious and can be provided better sooner than later. ^^


(cpradio) #6

Well, I think one solution is renaming Group ORGANISATION-BOARD to BOARD-ORGANISATION (if you need an immediate fix). Not sure what the programming correction will be (or how difficult it may be)


(Rafael dos Santos Silva) #7

If this only happens when we have an “-” on the group name a simple fix would be to disallow such symbol.


(cpradio) #8

Yep, that is a requirement. I took out the hyphen in my test case, and it no longer mentions the larger group when I use @SpecialForce to mention that smaller group. (So that’s another workaround @rriemann)


(Robert) #9

I don’t like the idea to disallow hyphens. I already have them. I suggest to change the regex to filter for group mentions.


(Tobias Eigen) #10

What about underscores? Can you test that? That’s what we use on our site.


(cpradio) #11

Using Special_Force for my Group name and mentioning it, did not also notify the Special group, so Underscores are also safe.


(Robert) #12

Maybe I have found the source of the issue. I’m running opensuse and virtualbox is requiring a different kernel that introduces some issues on my system. So far, I did not succeed to setup a Discourse developement environment. :frowning:

I hope I can provide some pieces here so that someone else (@sam) can prepare a patch to allow hyphens in group names.

The Regex to identify mentions has currently this structure: /\W@(\w{3,20})\b/

Underscores are in \w, the hyphen is not.

Therefore, the regex could be changed to: \W@([\w\-]{3,20})\b
Group mentions like @-new or @_new would be allowed though which is a bit confusing.

A spec should be added to ensure that @ORGANISATION-BOARD doesn’t match @ORGANISATION.


(Robert) #13

PR: fix: support for hyphens in group name by rriemann · Pull Request #4031 · discourse/discourse · GitHub


(Robert) #14

Hey @cpradio,

would you please test my pull request ? https://github.com/discourse/discourse/pull/40311

Even though the tests are passing, I have still troubles in the development version. Is something cached? I cannot really explain why it is not working locally and I cannot test on my production server.


(cpradio) #15

Definitely works! (from my limited testing)


(Sam Saffron) #16

Merged and further refined:

thanks heaps @rriemann


(Sam Saffron) #17