Skip to content

Conversation

@TBG-FR
Copy link
Contributor

@TBG-FR TBG-FR commented Feb 23, 2021

Clean version of #18913 (still worth mentionning it for the discussions in comments about "missing" search results")

Proposed changes

It has been reported that when searching for a message, the results were displaying with bugs : URLs where broken, emojis title too, and some results are missing. This PR aims to fix these issues.

Elements resolved:

Issue(s)

#18770 => reports that highlighted links, emojis (and mentions ?) are broken, as well as missing results
#18696 => reports that highlighted links are broken
#18456 => report that highlighted links are broken

How to test or reproduce

Go into a channel, and post these messages :

smile
😄
smile.com
smile-not.com
smilenot.com

Then search for the word smile in that channel. You'll notice that:

  • you can't click on links anymore (they're broken by <mark> tags)
  • if you hover on the smile emoji, its title is broken by <mark> tags too
  • the smilenot.com link isn't part of the results

Screenshots

See issues for screenshots

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves a current function)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Hotfix (a major bugfix that has to be merged asap)
  • Documentation Update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Changelog

Further comments

Broken links/emojis

I fixed the <mark> tag issue by doing three replace steps

  1. Using a (bit tricky) REGEX, we find every occurence of searchedText which is inside a title="..." or href="..." and replace searchedText in them by an unique UUID
  2. Using the previous line of code, we find every occurence of searchedText left and we mark it
  3. We find every occurence of the UUID and replace them with searchedText

I did this because I couldn't make a better REGEX, which would exclude 1 and find only 2. If you are able to do it, or if you see a better solution, feel free to comment ! Also, you may wonder "Why an UUID ?" : I used it because I thought that any arbitrary set of characters could end up being part of the initial search, and I think we're safe about that with a V4 UUID.

Considering the other issue, which we'll call "missing results", I searched in the whole project and found that it uses a Meteor function messageSearch. So I suspect Meteor for being responsible of that bug, but we need more investigation to be sure.

Related PR

Results highlighting has been implemented in #16166

@TBG-FR
Copy link
Contributor Author

TBG-FR commented Oct 7, 2021

For reference : PR #23309 / Issue #19369 / Issue #23285

@CLAassistant
Copy link

CLAassistant commented Dec 17, 2021

CLA assistant check
All committers have signed the CLA.

…s links, usernames, emojis (handles multiple matches)
@TBG-FR TBG-FR force-pushed the fix-search-marks branch from 67d2b10 to abaa57b Compare June 16, 2022 08:10
@TBG-FR
Copy link
Contributor Author

TBG-FR commented Jun 16, 2022

I just updated the PR to rebase on RocketChat:develop, and CLA is signed since Dec 2021.

As stated here, this PR will close 6 issues and 3 PRs :

We are dealing with that issue for such a long time now. There are several issues and PRs over the past year:

PR:

@debdutdeb would it be possible for you (or someone else) to review that PR ? We discussed it with @sampaiodiego in #18913 (Sep 2020 - Feb 2021), I since cleaned the PR, and everything looks good to go !

Hope we'll finally get rid of this issue, a long await one ! 💪

@TBG-FR
Copy link
Contributor Author

TBG-FR commented Sep 14, 2022

@debdutdeb @dudanogueira @sampaiodiego Could you guys review (and accept if it looks good to you) this PR ? There's a lot of issues (and now, many PRs) aiming to fix that one, showing how disturbing it is for users to have broken links (regular urls and mailto), emojis and user tags

Copy link
Member

@sampaiodiego sampaiodiego left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @TBG-FR thx for the deep investigation on this issue..

I was wondering if we could still use a single regex to do the replace.. I give it a try a come up with this:

msg = msg.replace(new RegExp(`(${searchedText})(?![^<]*>)`, 'gi'), (str) => `<mark>${str}</mark>`);

a tested very quick and got good results.. can you pls try it on your end to see if it works as expected as well?

@TBG-FR
Copy link
Contributor Author

TBG-FR commented Sep 29, 2022

hey @TBG-FR thx for the deep investigation on this issue..

I was wondering if we could still use a single regex to do the replace.. I give it a try a come up with this:

msg = msg.replace(new RegExp(`(${searchedText})(?![^<]*>)`, 'gi'), (str) => `<mark>${str}</mark>`);

a tested very quick and got good results.. can you pls try it on your end to see if it works as expected as well?

Thanks for your message, and for that improvement ! I finally tested it, and:

  • ✅ URIs aren't broken anymore (href)
  • ✅ Mails aren't broken anymore (mailto:)
  • ✅ Emojis titles are fixed too !

Good catch with that solution that stays simple 😄
Should I update this PR, or do you want to simply push a commit yourself ?

@sampaiodiego
Copy link
Member

that's great to know 😄

I'd be happy to accept that as a contribution.. so feel free to update this PR with it :)

@TBG-FR
Copy link
Contributor Author

TBG-FR commented Sep 30, 2022

PR updated ;) I also checked user tags (@smile) and their titles aren't broken anymore 🥳

@TBG-FR TBG-FR requested a review from sampaiodiego October 11, 2022 07:57
@sampaiodiego sampaiodiego merged commit 59d5c91 into RocketChat:develop Nov 3, 2022
gabriellsh added a commit to sidmohanty11/Rocket.Chat that referenced this pull request Nov 3, 2022
…ranch2

* 'develop' of github.com:RocketChat/Rocket.Chat: (1555 commits)
  Chore: Show better error logs (RocketChat#27156)
  [FIX] Message search breaking URL, usertags and emojis (RocketChat#20878)
  [NEW] REST API endpoint `/v1/oauth-apps.create` (RocketChat#27054)
  i18n: Language update from LingoHub 🤖 on 2022-10-31Z (RocketChat#27150)
  Chore: Convert client/views/directory/hooks to ts (RocketChat#26936)
  Chore: Convert client/views/directory/RoomTags to ts (RocketChat#26937)
  [FIX] UserCard not opening inside Threads (RocketChat#27096)
  [FIX] Gap between message content and message header when there's no text. (RocketChat#27165)
  Chore: docs grammar fix (RocketChat#26894)
  [FIX]  Removed mobile requirement for showing real name (RocketChat#26968)
  Chore: Cursor pointer to all the action buttons (RocketChat#24440)
  Chore: Bump actions/upload-artifact from 2 to 3 (RocketChat#27109)
  Chore: Enable PR Title Checker for forks (RocketChat#27144)
  Chore: Converting game center to typescript (RocketChat#26915)
  i18n: Language update from LingoHub 🤖 on 2022-10-24Z (RocketChat#27127)
  Chore: Add info log to remove all rooms method (RocketChat#27106)
  [IMPROVE] Quotes on E2EE Messages (RocketChat#26303)
  [NEW] REST API endpoint `/v1/rooms.delete` (RocketChat#26866)
  [FIX] Room Avatar being deleted after upload. (RocketChat#27060)
  Chore: Apps/Marketplace code organization (RocketChat#27061)
  ...
gabriellsh added a commit that referenced this pull request Nov 3, 2022
…llowArchived

* 'develop' of github.com:RocketChat/Rocket.Chat: (2426 commits)
  Chore: Show better error logs (#27156)
  [FIX] Message search breaking URL, usertags and emojis (#20878)
  [NEW] REST API endpoint `/v1/oauth-apps.create` (#27054)
  i18n: Language update from LingoHub 🤖 on 2022-10-31Z (#27150)
  Chore: Convert client/views/directory/hooks to ts (#26936)
  Chore: Convert client/views/directory/RoomTags to ts (#26937)
  [FIX] UserCard not opening inside Threads (#27096)
  [FIX] Gap between message content and message header when there's no text. (#27165)
  Chore: docs grammar fix (#26894)
  [FIX]  Removed mobile requirement for showing real name (#26968)
  Chore: Cursor pointer to all the action buttons (#24440)
  Chore: Bump actions/upload-artifact from 2 to 3 (#27109)
  Chore: Enable PR Title Checker for forks (#27144)
  Chore: Converting game center to typescript (#26915)
  i18n: Language update from LingoHub 🤖 on 2022-10-24Z (#27127)
  Chore: Add info log to remove all rooms method (#27106)
  [IMPROVE] Quotes on E2EE Messages (#26303)
  [NEW] REST API endpoint `/v1/rooms.delete` (#26866)
  [FIX] Room Avatar being deleted after upload. (#27060)
  Chore: Apps/Marketplace code organization (#27061)
  ...
gabriellsh added a commit to Kartik18g/Rocket.Chat that referenced this pull request Nov 3, 2022
* 'develop' of github.com:RocketChat/Rocket.Chat: (2462 commits)
  [FIX] Uploading Custom Sound files not working, but showing success (RocketChat#27177)
  Chore: Show better error logs (RocketChat#27156)
  [FIX] Message search breaking URL, usertags and emojis (RocketChat#20878)
  [NEW] REST API endpoint `/v1/oauth-apps.create` (RocketChat#27054)
  i18n: Language update from LingoHub 🤖 on 2022-10-31Z (RocketChat#27150)
  Chore: Convert client/views/directory/hooks to ts (RocketChat#26936)
  Chore: Convert client/views/directory/RoomTags to ts (RocketChat#26937)
  [FIX] UserCard not opening inside Threads (RocketChat#27096)
  [FIX] Gap between message content and message header when there's no text. (RocketChat#27165)
  Chore: docs grammar fix (RocketChat#26894)
  [FIX]  Removed mobile requirement for showing real name (RocketChat#26968)
  Chore: Cursor pointer to all the action buttons (RocketChat#24440)
  Chore: Bump actions/upload-artifact from 2 to 3 (RocketChat#27109)
  Chore: Enable PR Title Checker for forks (RocketChat#27144)
  Chore: Converting game center to typescript (RocketChat#26915)
  i18n: Language update from LingoHub 🤖 on 2022-10-24Z (RocketChat#27127)
  Chore: Add info log to remove all rooms method (RocketChat#27106)
  [IMPROVE] Quotes on E2EE Messages (RocketChat#26303)
  [NEW] REST API endpoint `/v1/rooms.delete` (RocketChat#26866)
  [FIX] Room Avatar being deleted after upload. (RocketChat#27060)
  ...
gabriellsh added a commit to im-adithya/Rocket.Chat that referenced this pull request Nov 3, 2022
…password-change

* 'develop' of github.com:RocketChat/Rocket.Chat: (2885 commits)
  [FIX] Uploading Custom Sound files not working, but showing success (RocketChat#27177)
  Chore: Show better error logs (RocketChat#27156)
  [FIX] Message search breaking URL, usertags and emojis (RocketChat#20878)
  [NEW] REST API endpoint `/v1/oauth-apps.create` (RocketChat#27054)
  i18n: Language update from LingoHub 🤖 on 2022-10-31Z (RocketChat#27150)
  Chore: Convert client/views/directory/hooks to ts (RocketChat#26936)
  Chore: Convert client/views/directory/RoomTags to ts (RocketChat#26937)
  [FIX] UserCard not opening inside Threads (RocketChat#27096)
  [FIX] Gap between message content and message header when there's no text. (RocketChat#27165)
  Chore: docs grammar fix (RocketChat#26894)
  [FIX]  Removed mobile requirement for showing real name (RocketChat#26968)
  Chore: Cursor pointer to all the action buttons (RocketChat#24440)
  Chore: Bump actions/upload-artifact from 2 to 3 (RocketChat#27109)
  Chore: Enable PR Title Checker for forks (RocketChat#27144)
  Chore: Converting game center to typescript (RocketChat#26915)
  i18n: Language update from LingoHub 🤖 on 2022-10-24Z (RocketChat#27127)
  Chore: Add info log to remove all rooms method (RocketChat#27106)
  [IMPROVE] Quotes on E2EE Messages (RocketChat#26303)
  [NEW] REST API endpoint `/v1/rooms.delete` (RocketChat#26866)
  [FIX] Room Avatar being deleted after upload. (RocketChat#27060)
  ...
@ggazzo ggazzo mentioned this pull request Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants