Fix boundaries during mention parsing #1625
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I believe the intention behind what should be parsed as a mention is anything that starts with an
@
and only contains valid username characters (+ profile path) and is delimited by whitespace. However, the current code does not do that but allows characters before@
and after the username:This results in the following—IMO broken—highlighting on the client:
I also think client and server might not parse the same stuff in some cases. This means that a mention that the client would show as a mention wouldn't be considered a mention on the server so the stacker wouldn't actually get a notification.
This PR intends to fix that. Ideally, we would be able to simply use
\b
to match word boundarise, but since@
isn't considered a word character and characters like:
are also considered a boundary, this doesn't work. So I decided to use positive lookbehind(?<=\s|^)
and positive lookahead(?=\s|$)
to fix the highlighting:This results in the following highlighting on the client:
Since only updating the regexp is not enough but this also requires testing of:
This turned out to be quite a rabbit hole, so I’m leaving this PR as a source of future inspiration and as a reminder, that there is something wrong with mentions IMO.
and because we don't have enough draft PRs already
Additional Context
Was anything unclear during your work on this PR? Anything we should definitely take a closer look at?
Checklist
Are your changes backwards compatible? Please answer below:
On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:
For frontend changes: Tested on mobile, light and dark mode? Please answer below:
Did you introduce any new environment variables? If so, call them out explicitly here: