Message highlighting matches longer names with the same beginning

Bug #264231 reported by Nathan Howell
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Gwibber
Fix Released
Undecided
Greg Grossmeier

Bug Description

If my username is "user", messages containing "@username" will be incorrectly highlighted as replies to me.

Related branches

Revision history for this message
Greg Grossmeier (greg.grossmeier) wrote :

Confirmed with gwibber 0.7~bzr102~intrepid~ppa2 (Intrepid)

Changed in gwibber:
status: New → Confirmed
Revision history for this message
Greg Grossmeier (greg.grossmeier) wrote :

So, it was a simple fix.

The line testing if a message is a reply to you had:
self.is_reply = ("@%s" % self.username) in self.text

but it should be:
self.is_reply = ("@%s " % self.username) in self.text

Which just adds a space to the string test.

This was in both microblog/twitter.py and microblog/identica.py

Attached is a patch (bzr diff) for these two files.

Revision history for this message
Greg Grossmeier (greg.grossmeier) wrote :

Screenshot "proving" my patch. (ignore the horrible them)

Changed in gwibber:
status: Confirmed → In Progress
assignee: nobody → greg.grossmeier
Revision history for this message
Ryan Paul (segphault) wrote :

Thanks for working on this!

Unfortunately, I'm pretty sure that your solution won't account for punctuation that might follow the nickname. For instance, I think that it will fail to highlight the message if it contains "segphault:" instead of "segphault ". It could also fail for messages that have the user's nick at the very end of the string.

I've been thinking about how to solve this too, and I'm having a hard time coming up with a viable solution that doesn't involve a regular expression.

Revision history for this message
wolfger (wolfger) wrote :

Why are you trying so hard to avoid a regex when a regex would solve the problem fairly easily?
Is it possible for a username to end in punctuation? That would be problematic... Otherwise, I think you only need to look for "@user ", "@user: ", "@user, ", "@user. ", "@user) ", "@user! ", or "@user? ". If, on the other hand, it's possible to have both "user" and "user!" as usernames, not even a regex will save you.

Revision history for this message
Greg Grossmeier (greg.grossmeier) wrote :

Fine, regex it is :)

As identica (and I assume twitter) requires all usernames to be alphanumeric, this line should replace line 32 in both identica.py and twitter.py:

    self.is_reply = re.compile("@%s[\W]+" % self.username).search(self.text)

screenshot proof attached

Revision history for this message
Greg Grossmeier (greg.grossmeier) wrote :

And a patch for easy applying/reviewing.

Revision history for this message
Greg Grossmeier (greg.grossmeier) wrote :

And a patch for easy applying/reviewing.

Revision history for this message
Ryan Paul (segphault) wrote :

Thanks! Committed in rev 115.

Changed in gwibber:
status: In Progress → Fix Released
Revision history for this message
Greg Grossmeier (greg.grossmeier) wrote :

Ryan,

Sorry, I missed the case where the username comes at the end of the line. But, accommodating for that isn't bad either.

Now that line should look like:
    self.is_reply = re.compile("@%s[\W]+|@%s$" % (self.username, self.username)).search(self.text)

With that line it reports these are replies:
"blah @greg!"
"blah @greg blah"
"blah @greg! blah"
"blah blah blah @greg" <-- This one wasn't identified by rev 115
"blah @greg!!!!one"
"blah @greg!!!!!!!!"
"@greg blah"

And these not as replies:
"blah @gregory"
"blah @gregory!"
"@gregory blah"

Attached is another patch which applies to rev 115.

Sorry about that.

Revision history for this message
Ryan Paul (segphault) wrote :

Thanks! I've updated it with your new regex in rev 117.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.