[openstreetmap/openstreetmap-website] Shorten matching urls in linkify (PR #5844)

Marwin Hochfelsner notifications at github.com
Tue Mar 25 05:58:07 UTC 2025


@hlfan commented on this pull request.



> @@ -76,11 +76,13 @@ def sanitize(text)
     end
 
     def linkify(text, mode = :urls)
-      if text.html_safe?
-        Rinku.auto_link(text, mode, tag_builder.tag_options(:rel => "nofollow noopener noreferrer")).html_safe
-      else
-        Rinku.auto_link(text, mode, tag_builder.tag_options(:rel => "nofollow noopener noreferrer"))
-      end
+      link_attr = tag_builder.tag_options(:rel => "nofollow noopener noreferrer")
+      Rinku.auto_link(ERB::Util.html_escape(text), mode, link_attr) do |url|
+        %r{^https?://([^/]*)(.*)$}.match(url) do |m|

Maybe put the www subdomain check into the regex:
```suggestion
        %r{^https?://(?:www\.)?([^/]*)(.*)$}.match(url) do |m|
```
Otherwise linkify_hosts / linkify_domains could get unwieldy long when including all the domains listed in [osm.wiki/wiki/Domain names](//osm.wiki/wiki/Domain_names):
```yaml
["openstreetmap.com", "openstreetmap.net", "openstreetmaps.org", "openmaps.org", "osm.org"]
```

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

Message ID: <openstreetmap/openstreetmap-website/pull/5844/review/2712466589 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20250324/e5849ea9/attachment.htm>


More information about the rails-dev mailing list