-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix issue #6614: Support spaces in @mentions using quotes #6616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix issue #6614: Support spaces in @mentions using quotes #6616
Conversation
|
And how am I supposed to tag this user named "Yo"? |
b4e6bad to
03656fa
Compare
|
Thanks for pointing that out @hlfan ! I realized the original regex didn't account for names containing quotes like "Yo". I've updated the logic to support single quotes as wrappers, so you can now tag that user simply as @'Yo'. This update also handles cases where Markdown converts standard quotes into "smart" curly quotes, preventing broken links. I've added a test case to cover this scenario as well. |
03656fa to
816d260
Compare
hlfan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Sorry for that @hlfan ! |
|
Well, that's the crux of the issue. We couldn't even deny newlines, as there's already one user with \r\n in the name: https://www.openstreetmap.org/user/Mohamedkaizen%0D%0AMohamedkaizen I think the way to reduce this risk as much as possible is to use a different delimitation character that is more commonly related to URLs than casual text. Right now, the longest name of a contributor is bwdlqwbdjlbqlwdjbqlwjdbqljwbdlqwjbdlqwjdblqjwbdlqjwdbqlwjdblqwdblqjbdlqjwbdljqbwdljqwbdlqbwdbqwdblqwdlqwbdlbdlqbwldbqlwbdlqbwdlqbdlqbdljwbdlqwbdwlbqlwdblqwbdjlqwbdjlqwbdljqwbdljqbwdljqbdlqwbdlqbdljqbdljqbwdljbqldbqlwdbljqwbdljqwdbqlwdbqlwjdbqlwdbqlw at 249 chars, so none of these suggestions would be inclusive. And database validation is probably too much of a slowdown for how often this library is called. |
|
Do we really have to fix the issue for all? we could keep them in (negative) unit test (with explaining comments) to declare the explicit simplicity. |
|
But where do you draw the line? Do you want users to need to escape whitespace or not? |
| private | ||
|
|
||
| def linkify_users(text) | ||
| regex = /(?<!\w)@(?:“([^”]+?)”|”([^”]+?)”|‘([^’]+?)’|’([^’]+?)’|"([^"]+?)"|'([^']+?)'|(\w+))/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some way to match that doesn't involve an unreadable regular expression?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also a lot of logic in this regular expression that is not tested. It looks like it matches
“”””‘’’’""''
Should we have a test that shows that it doesn't linkify something like @"foo'? What happens if there are multiple potential matches? e.g. @“foo@”bar”
IMO spaces could be supported. But we should ignore other white space or |
|
I think we should go in a different direction. This solution would require users to learn a new syntax that is not obvious, particularly as it's not a common convention that they may have learned at other apps. And that's before going into the side-effects that are being discussed above. I have created an issue at #6635, describing what I think we should do instead. |
|
@pnorman I gave the I'm thinking of sticking with the simpler implementation. In my opinion, the trade-off of having hard-to-maintain code isn't worth it for such a rare edge case. The current version handles all standard and smart quotes correctly. I've reverted to the cleaner version—let me know if you're okay with this approach! |
|
@pablobm Thanks for linking that issue! I just read through the discussion in #6635. Honestly, while a proper dropdown/User-ID system would be the ideal solution eventually, it looks like it's facing some pretty massive blockers right now. As 1ec5 and TomHughes pointed out, we don't have a User Search API, and moving away from plain-text comments to support hidden IDs would likely require a full Rich Text Editor overhaul. I think this PR is the best path forward for now because it solves the bug immediately without needing a massive architectural rewrite. We can always upgrade to the "perfect" system later if those technical hurdles get cleared, but I don't think we should block this fix while waiting for that to happen. |

Description
Fixes #6614.
This PR updates the
RichText#linkify_usersmethod to support user mentions containing spaces by allowing quoted syntax (e.g.,@"Open Mapper").Key changes:
"), smart quotes (“”), and escaped entities ("), ensuring compatibility with the Markdown renderer.(?<!\w)to ensure that email addresses (e.g.,[email protected]) are not accidentally parsed as mentions.@symbol is replaced with the HTML entity@to prevent subsequent parsers (likeexpand_link_shorthands) from detecting the mention a second time.How has this been tested?
test_linkify_username_with_spacetotest/lib/rich_text_test.rbto verify that quoted mentions are correctly parsed into relative links with safe HTML output.RichTextTestsuite (bundle exec rails test test/lib/rich_text_test.rb) to confirm that standard mentions (@user) and email addresses still function correctly.rubocop.