From 9feb1f4b404bf2c7d9b659b281e470e6f04bba51 Mon Sep 17 00:00:00 2001 From: NeatNit Date: Thu, 3 Apr 2025 18:24:51 +0300 Subject: [PATCH] add dir="auto" to linkified links and replicate openstreetmap#5850 in ApplicationHelper --- app/helpers/application_helper.rb | 5 +++-- lib/rich_text.rb | 2 +- test/helpers/application_helper_test.rb | 4 ++-- test/helpers/browse_tags_helper_test.rb | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 86a3d56cd..1b04b78ed 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2,10 +2,11 @@ module ApplicationHelper require "rexml/document" def linkify(text) + link_attr = 'rel="nofollow" dir="auto"' if text.html_safe? - Rinku.auto_link(text, :urls, tag_builder.tag_options(:rel => "nofollow")).html_safe + Rinku.auto_link(text, :urls, link_attr).html_safe else - Rinku.auto_link(ERB::Util.h(text), :urls, tag_builder.tag_options(:rel => "nofollow")).html_safe + Rinku.auto_link(ERB::Util.h(text), :urls, link_attr).html_safe end end diff --git a/lib/rich_text.rb b/lib/rich_text.rb index 1d5ebab76..43b2c324b 100644 --- a/lib/rich_text.rb +++ b/lib/rich_text.rb @@ -74,7 +74,7 @@ module RichText end def linkify(text, mode = :urls) - link_attr = 'rel="nofollow noopener noreferrer"' + link_attr = 'rel="nofollow noopener noreferrer" dir="auto"' Rinku.auto_link(ERB::Util.html_escape(text), mode, link_attr) do |url| url = shorten_host(url, Settings.linkify_hosts, Settings.linkify_hosts_replacement) shorten_host(url, Settings.linkify_wiki_hosts, Settings.linkify_wiki_hosts_replacement) do |path| diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index 524851e63..20ae54f1c 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -9,11 +9,11 @@ class ApplicationHelperTest < ActionView::TestCase html = linkify(text) assert_predicate html, :html_safe? - assert_dom_equal "Test #{link} is <b>made</b> into a link", html + assert_dom_equal "Test #{link} is <b>made</b> into a link", html html = linkify(text.html_safe) assert_predicate html, :html_safe? - assert_dom_equal "Test #{link} is made into a link", html + assert_dom_equal "Test #{link} is made into a link", html end %w[test@example.com mailto:test@example.com].each do |link| diff --git a/test/helpers/browse_tags_helper_test.rb b/test/helpers/browse_tags_helper_test.rb index 990aed5e4..16351510a 100644 --- a/test/helpers/browse_tags_helper_test.rb +++ b/test/helpers/browse_tags_helper_test.rb @@ -62,10 +62,10 @@ class BrowseTagsHelperTest < ActionView::TestCase assert_dom_equal "foo@example.com", html html = format_value("source", "https://example.com") - assert_dom_equal "https://example.com", html + assert_dom_equal "https://example.com", html html = format_value("source", "https://example.com;hello;https://example.net") - assert_dom_equal "https://example.com;hello;https://example.net", html + assert_dom_equal "https://example.com;hello;https://example.net", html end def test_wiki_link -- 2.39.5