[openstreetmap/openstreetmap-website] Fix issue #6614: Support spaces in @mentions using quotes (PR #6616)

Anshul Zilpe notifications at github.com
Sun Dec 14 15:47:12 UTC 2025


### Description
Fixes #6614.

This PR updates the `RichText#linkify_users` method to support user mentions containing spaces by allowing quoted syntax (e.g., `@"Open Mapper"`).

**Key changes:**
* **Updated Regex:** Now detects mentions enclosed in quotes.
* **Quote Handling:** Supports straight quotes (`"`), smart quotes (`“”`), and escaped entities (`"`), ensuring compatibility with the Markdown renderer.
* **Email Protection:** Added a negative lookbehind `(?<!\w)` to ensure that email addresses (e.g., `user at example.com`) are not accidentally parsed as mentions.
* **Prevented Double-Linking:** The visible `@` symbol is replaced with the HTML entity `&#64;` to prevent subsequent parsers (like `expand_link_shorthands`) from detecting the mention a second time.

### How has this been tested?
* **New Test Case:** Added `test_linkify_username_with_space` to `test/lib/rich_text_test.rb` to verify that quoted mentions are correctly parsed into relative links with safe HTML output.
* **Regression Testing:** Ran the full `RichTextTest` suite (`bundle exec rails test test/lib/rich_text_test.rb`) to confirm that standard mentions (`@user`) and email addresses still function correctly.
* **Linting:** Verified code style compliance using `rubocop`.
You can view, comment on, or merge this pull request online at:

  https://github.com/openstreetmap/openstreetmap-website/pull/6616

-- Commit Summary --

  * Fix issue #6614: Support spaces in @mentions using quotes

-- File Changes --

    M lib/rich_text.rb (11)
    M test/lib/rich_text_test.rb (12)

-- Patch Links --

https://github.com/openstreetmap/openstreetmap-website/pull/6616.patch
https://github.com/openstreetmap/openstreetmap-website/pull/6616.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/6616
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/6616 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20251214/13f76bf9/attachment.htm>


More information about the rails-dev mailing list